added formatting settings
This commit is contained in:
parent
66a52435d1
commit
eb8fdb1a46
2 changed files with 60 additions and 16 deletions
41
README.md
41
README.md
|
|
@ -62,4 +62,43 @@ Copy the generated .mu files from the output folder to the NN node's `pages` fol
|
||||||
$ cp -R output/* ~/.nomadnetwork/storage/pages
|
$ cp -R output/* ~/.nomadnetwork/storage/pages
|
||||||
```
|
```
|
||||||
|
|
||||||
Run your node and serve the pages....
|
Run your node and serve the pages....
|
||||||
|
|
||||||
|
## Additional Formatting
|
||||||
|
|
||||||
|
Since micron templates do not support styling like CSS and Markdown is a strict content-only markup language all the color styling needs to be done using micron tags in the template files themselves.
|
||||||
|
|
||||||
|
Micron-blog offers a few Settings that allow to set enclosing tags for some of the inline and block elements that are rendered by Pelican:
|
||||||
|
|
||||||
|
```Python
|
||||||
|
MICRON_EMPHASIS_FORMAT = []
|
||||||
|
MICRON_STRONG_FORMAT = []
|
||||||
|
MICRON_LINK_FORMAT = []
|
||||||
|
MICRON_CODE_FORMAT = []
|
||||||
|
MICRON_HEADER_FORMAT = []
|
||||||
|
MICRON_QUOTE_FORMAT = []
|
||||||
|
MICRON_LIST_FORMAT = []
|
||||||
|
```
|
||||||
|
|
||||||
|
Each of them taks a list of exactly two tag definitions, one for the left and one for the right enclosing tag. For example, if you want to define all rendered links to be blue and underlined and all emphasized text to be yellow you could define the following settings in `pelicanconfig.py`:
|
||||||
|
|
||||||
|
```Python
|
||||||
|
MICRON_LINK_FORMAT = ['`F00f`_', '`_`f']
|
||||||
|
MICRON_EMPHASIS_FORMAT = ['`Fff0', '`f']
|
||||||
|
```
|
||||||
|
|
||||||
|
Now links created as:
|
||||||
|
```Markdown
|
||||||
|
[title](url)
|
||||||
|
*emphasized text*
|
||||||
|
```
|
||||||
|
will be rendered as:
|
||||||
|
```
|
||||||
|
`F00f`_`[title`url]`_`f
|
||||||
|
`Fff0`*emphasized text`*`f
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want the same settings to be honoured by the templates, they need to be implemented respecively. The settings are accessible by the templates:
|
||||||
|
```jinja
|
||||||
|
{{ MICRON_LINK_FORMAT[0] }}`[{{ p.title }}`:/{{ p.url }}]{{ MICRON_LINK_FORMAT[1] }}
|
||||||
|
```
|
||||||
|
|
@ -63,6 +63,7 @@ def render_underlined_html(self, token, state) -> str:
|
||||||
class MicronRenderer(MarkdownRenderer):
|
class MicronRenderer(MarkdownRenderer):
|
||||||
"""A renderer to format Micron text."""
|
"""A renderer to format Micron text."""
|
||||||
NAME = 'micron'
|
NAME = 'micron'
|
||||||
|
settings = {}
|
||||||
|
|
||||||
def __call__(self, tokens, state: BlockState):
|
def __call__(self, tokens, state: BlockState):
|
||||||
out = self.render_tokens(tokens, state)
|
out = self.render_tokens(tokens, state)
|
||||||
|
|
@ -78,31 +79,30 @@ class MicronRenderer(MarkdownRenderer):
|
||||||
return token['raw']
|
return token['raw']
|
||||||
|
|
||||||
def emphasis(self, token: Dict[str, Any], state: BlockState) -> str:
|
def emphasis(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return '`*' + self.render_children(token, state) + '`*'
|
fpre, fpost = self.settings.get('MICRON_EMPHASIS_FORMAT', ['', ''])
|
||||||
|
return fpre + '`*' + self.render_children(token, state) + '`*' + fpost
|
||||||
|
|
||||||
def strong(self, token: Dict[str, Any], state: BlockState) -> str:
|
def strong(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return '`!' + self.render_children(token, state) + '`!'
|
fpre, fpost = self.settings.get('MICRON_STRONG_FORMAT', ['', ''])
|
||||||
|
return fpre + '`!' + self.render_children(token, state) + '`!' + fpost
|
||||||
|
|
||||||
def link(self, token: Dict[str, Any], state: BlockState) -> str:
|
def link(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
|
fpre, fpost = self.settings.get('MICRON_LINK_FORMAT', ['', ''])
|
||||||
label = token.get('label')
|
label = token.get('label')
|
||||||
text = self.render_children(token, state)
|
text = self.render_children(token, state)
|
||||||
out = '`[' + text + '`'
|
out = fpre
|
||||||
if label:
|
out += '`[' + text + '`'
|
||||||
return out + '`[' + label + '`'
|
|
||||||
attrs = token['attrs']
|
attrs = token['attrs']
|
||||||
url = attrs['url']
|
url = attrs['url']
|
||||||
if text == url:
|
|
||||||
return '`[' + text + '`'
|
|
||||||
elif 'mailto:' + text == url:
|
|
||||||
return '`[' + text + '`'
|
|
||||||
out += url
|
out += url
|
||||||
return out + ']'
|
return out + ']' + fpost
|
||||||
|
|
||||||
def image(self, token: Dict[str, Any], state: BlockState) -> str:
|
def image(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return self.link(token, state)
|
return self.link(token, state)
|
||||||
|
|
||||||
def codespan(self, token: Dict[str, Any], state: BlockState) -> str:
|
def codespan(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return '`=' + token['raw'] + '`='
|
fpre, fpost = self.settings.get('MICRON_CODE_FORMAT', ['', ''])
|
||||||
|
return fpre + '`=' + token['raw'] + '`=' + fpost
|
||||||
|
|
||||||
def linebreak(self, token: Dict[str, Any], state: BlockState) -> str:
|
def linebreak(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return ' \n'
|
return ' \n'
|
||||||
|
|
@ -121,12 +121,14 @@ class MicronRenderer(MarkdownRenderer):
|
||||||
return text + '\n\n'
|
return text + '\n\n'
|
||||||
|
|
||||||
def heading(self, token: Dict[str, Any], state: BlockState) -> str:
|
def heading(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
|
fpre, fpost = self.settings.get('MICRON_HEADER_FORMAT', ['', ''])
|
||||||
level = token['attrs']['level']
|
level = token['attrs']['level']
|
||||||
if level > 3:
|
if level > 3:
|
||||||
level = 3
|
level = 3
|
||||||
marker = '>' * level
|
marker = '>' * level
|
||||||
text = self.render_children(token, state)
|
text = self.render_children(token, state)
|
||||||
return marker + ' ' + text + '\n\n'
|
return fpre + marker + ' ' + text + fpost + '\n\n'
|
||||||
|
|
||||||
def thematic_break(self, token: Dict[str, Any], state: BlockState) -> str:
|
def thematic_break(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return '-\n\n'
|
return '-\n\n'
|
||||||
|
|
||||||
|
|
@ -134,15 +136,17 @@ class MicronRenderer(MarkdownRenderer):
|
||||||
return self.render_children(token, state) + '\n'
|
return self.render_children(token, state) + '\n'
|
||||||
|
|
||||||
def block_code(self, token: Dict[str, Any], state: BlockState) -> str:
|
def block_code(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
|
fpre, fpost = self.settings.get('MICRON_CODE_FORMAT', ['', ''])
|
||||||
code = token['raw']
|
code = token['raw']
|
||||||
if code and code[-1] != '\n':
|
if code and code[-1] != '\n':
|
||||||
code += '\n'
|
code += '\n'
|
||||||
marker = '`='
|
marker = '`='
|
||||||
return marker + '\n' + code + marker + '\n\n'
|
return fpre + marker + '\n' + code + marker + fpost + '\n\n'
|
||||||
|
|
||||||
def block_quote(self, token: Dict[str, Any], state: BlockState) -> str:
|
def block_quote(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
|
fpre, fpost = self.settings.get('MICRON_QUOTE_FORMAT', ['', ''])
|
||||||
text = indent(self.render_children(token, state), '>>>>')
|
text = indent(self.render_children(token, state), '>>>>')
|
||||||
return text + '\n\n'
|
return fpre + text + fpost + '\n\n'
|
||||||
|
|
||||||
def block_html(self, token: Dict[str, Any], state: BlockState) -> str:
|
def block_html(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return ''
|
return ''
|
||||||
|
|
@ -151,7 +155,8 @@ class MicronRenderer(MarkdownRenderer):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def list(self, token: Dict[str, Any], state: BlockState) -> str:
|
def list(self, token: Dict[str, Any], state: BlockState) -> str:
|
||||||
return render_list(self, token, state)
|
fpre, fpost = self.settings.get('MICRON_LIST_FORMAT', ['', ''])
|
||||||
|
return fpre + render_list(self, token, state) + fpost
|
||||||
|
|
||||||
# === M A R K D O W N T O M I C R O N R E A D E R ===
|
# === M A R K D O W N T O M I C R O N R E A D E R ===
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue