Code Monkey home page Code Monkey logo

jw-obsidian-micromark-extension's Introduction

jw-obsidian-micromark-extension

npm install jw-obsidian-micromark-extension

https://github.com/Jabberwocky238/micromicro

micromark extensions to support Obsidian asset & link.

Use

import { micromark } from 'micromark'
import { jwObsidian, jwObsidianHtml } from 'jw-obsidian-micromark-extension'

const str = [
  '[[this is a link]]',
  '![[this is an image.png]]',
  '==this is highlight (mark)==',
  '==robus=tness==',
].join('\r\n\r\n')

const result = micromark(str, {
  extensions: [jwObsidian()],
  htmlExtensions: [jwObsidianHtml()],
})

Yields:

<p><a href="/this is a link.md">this is a link</a></p>
<p><img src="/assets/this is an image.png" alt="/assets/this is an image.png"></img></p>
<p><mark>this is highlight (mark)</mark></p>
<p><mark>robus=tness</mark></p>

Options

there are 5 options for jwObsidianHtml:

  • baseDir: string, default ''
  • edit: function, default (token) => token
  • edit4image: function, default (token) => ['assets', token].join('/')
  • edit4link: function, default (token) => [token, '.md'].join('')
  • edit4mark: function, default (token) => token

baseDir

micromark('[[OCA 我草泥马————asd_ _]]', {
    extensions: [jwObsidian()],
    htmlExtensions: [jwObsidianHtml({ baseDir: 'markdown' })],
}),
'<p><a href="/markdown/OCA 我草泥马————asd_ _.md">OCA 我草泥马————asd_ _</a></p>'

edit

const edit = (token) => {
    return "/markdown" + token
}
assert.equal(
    micromark('[[OCA 我草泥马————asd_ _]]', {
        extensions: [jwObsidian()],
        htmlExtensions: [jwObsidianHtml({ edit })],
    }),
    '<p><a href="/markdown/OCA 我草泥马————asd_ _.md">OCA 我草泥马————asd_ _</a></p>'
)

edit4link

const _map = new Map([['OCA 我草泥马————asd_ _', ['concepts', 'OCA 我草泥马————asd_ _.md']]])
const edit4link = (token) => {
    const candidate = _map.get(token)
    if (candidate) {
        token = candidate.join('/')
    }
    return "/markdown/" + token
}
// console.log(reflexMap)
assert.equal(
    micromark('[[OCA 我草泥马————asd_ _]]', {
        extensions: [jwObsidian()],
        htmlExtensions: [jwObsidianHtml({ edit4link })],
    }),
    '<p><a href="/markdown/concepts/OCA 我草泥马————asd_ _.md">OCA 我草泥马————asd_ _</a></p>'
)

PS: edit4image and edit4mark are literally the same as edit4link

PPS: edit4sth run before edit, in edit4sth you will get directly the raw token, but in edit you will get the token after edit4sth, which is exact the token filling the certain slot. So if not necessary, do not use edit.

Thanks

micromark-extension-wiki-link micromark-extension-directive

License

MIT

jw-obsidian-micromark-extension's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.