Skip to content

Instantly share code, notes, and snippets.

@hagenburger
Created July 1, 2018 21:50
Show Gist options
  • Save hagenburger/36ac45c3485ab337977045f24b751060 to your computer and use it in GitHub Desktop.
Save hagenburger/36ac45c3485ab337977045f24b751060 to your computer and use it in GitHub Desktop.
const Config = require('../lib/config')
const Document = require('../lib/document')
const config = new Config()
config.commands[':'] = function (pi) {
pi.renderer.config.parseInfoString(pi.content.trim(), pi)
}
config.commands['lol'] = function (pi) {
return 'rofl'
}
config.addInfoStringParser(/\[([a-z0-9-]+)(?:=([^\]]+))?\]/i, function (match, name, value) {
value = value || name
if (value.match(/^(".*"|'.*')$/)) value = value.substring(1, value.length - 1)
this.element.setAttribute(name, value)
})
const source = `
# Headline <?: [lang=en] ?>
Lorem ipsum dolor sit amet <?: [lang="de"] ?>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
TODO: Here only the <a> should get the target. The <p> should not get it:
A [link <?: [target=_blank] ?>](https://livingstyleguide.org).
A [disabled link <?: [disabled] ?>](https://livingstyleguide.org).
TODO: Here the <img> instead of the <p> should get the width:
![Test<?: [width=100%] ?> <?lol?>](text.png)
~~~ html [data-info="123"]
<p></p>
~~~
| Table <?: [align=right] ?> | Table |
|----------------------------|-------------------------------|
| Table | Table <?: [align='center'] ?> |
`
const doc = new Document(source, config)
doc.renderDocument().then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment