revised callout content parsing, which made nested callouts automagically work
This commit is contained in:
parent
dd01597ac5
commit
aa431fe361
|
@ -867,11 +867,13 @@ class ObsidianStyleBlockquotes(Extension):
|
||||||
CALLOUT = re.compile(r'^\[!([a-z]+)\]([-+])?(?:[ ]+(.*))?')
|
CALLOUT = re.compile(r'^\[!([a-z]+)\]([-+])?(?:[ ]+(.*))?')
|
||||||
CALLOUT_DEFICON = 'pencil'
|
CALLOUT_DEFICON = 'pencil'
|
||||||
CALLOUT_ICONS = {
|
CALLOUT_ICONS = {
|
||||||
|
'example': 'list',
|
||||||
'faq': 'circle-help',
|
'faq': 'circle-help',
|
||||||
'help': 'circle-help',
|
'help': 'circle-help',
|
||||||
'info': 'info',
|
'info': 'info',
|
||||||
'question': 'circle-help',
|
'question': 'circle-help',
|
||||||
'tip': 'flame'
|
'tip': 'flame',
|
||||||
|
'todo': 'circle-check'
|
||||||
}
|
}
|
||||||
|
|
||||||
def normal_blockquote(self, parent: etree.Element, block: str) -> None:
|
def normal_blockquote(self, parent: etree.Element, block: str) -> None:
|
||||||
|
@ -920,15 +922,9 @@ class ObsidianStyleBlockquotes(Extension):
|
||||||
if folding:
|
if folding:
|
||||||
styleval = 'display: none;' if folding == '-' else ''
|
styleval = 'display: none;' if folding == '-' else ''
|
||||||
content_div.attrib['style'] = styleval
|
content_div.attrib['style'] = styleval
|
||||||
first = True
|
self.parser.state.set('callout')
|
||||||
for line in lines:
|
self.parser.parseBlocks(content_div, ['\n'.join(lines)])
|
||||||
if first:
|
self.parser.state.reset()
|
||||||
first = False
|
|
||||||
else:
|
|
||||||
etree.SubElement(content_div, 'br')
|
|
||||||
self.parser.state.set('list')
|
|
||||||
self.parser.parseBlocks(content_div, [line])
|
|
||||||
self.parser.state.reset()
|
|
||||||
|
|
||||||
def run(self, parent: etree.Element, blocks: list[str]) -> None:
|
def run(self, parent: etree.Element, blocks: list[str]) -> None:
|
||||||
block = blocks.pop(0)
|
block = blocks.pop(0)
|
||||||
|
@ -948,8 +944,32 @@ class ObsidianStyleBlockquotes(Extension):
|
||||||
else:
|
else:
|
||||||
self.normal_blockquote(parent, block)
|
self.normal_blockquote(parent, block)
|
||||||
|
|
||||||
|
class CalloutLinesProcessor(BlockProcessor):
|
||||||
|
def test(self, parent: etree.Element, block: str) -> bool:
|
||||||
|
return self.parser.state.isstate('callout')
|
||||||
|
|
||||||
|
def run(self, parent: etree.Element, blocks: list[str]) -> bool:
|
||||||
|
block = blocks.pop(0)
|
||||||
|
if block.strip():
|
||||||
|
sibling = self.lastChild(parent)
|
||||||
|
lines = block.split('\n')
|
||||||
|
for line in lines:
|
||||||
|
if sibling is not None:
|
||||||
|
if sibling.tail:
|
||||||
|
sibling = etree.SubElement(parent, 'br')
|
||||||
|
else:
|
||||||
|
if parent.text:
|
||||||
|
sibling = etree.SubElement(parent, 'br')
|
||||||
|
else:
|
||||||
|
parent.text = line
|
||||||
|
continue
|
||||||
|
sibling.tail = line
|
||||||
|
return True
|
||||||
|
|
||||||
def extendMarkdown(self, md) -> None:
|
def extendMarkdown(self, md) -> None:
|
||||||
md.parser.blockprocessors.register(ObsidianStyleBlockquotes.ObsidianBlockQuote(md.parser), 'quote', 20)
|
md.parser.blockprocessors.register(ObsidianStyleBlockquotes.ObsidianBlockQuote(md.parser), 'quote', 20)
|
||||||
|
md.parser.blockprocessors.register(ObsidianStyleBlockquotes.CalloutLinesProcessor(md.parser),
|
||||||
|
'callout-text', 11)
|
||||||
|
|
||||||
|
|
||||||
def create_markdown_parser(context: Context) -> markdown.Markdown:
|
def create_markdown_parser(context: Context) -> markdown.Markdown:
|
||||||
|
|
|
@ -63,6 +63,9 @@ th {
|
||||||
background-color: rgba(var(--callout-color), 0.1);
|
background-color: rgba(var(--callout-color), 0.1);
|
||||||
padding: 12px 12px 12px 24px;
|
padding: 12px 12px 12px 24px;
|
||||||
}
|
}
|
||||||
|
.callout[data-callout="example"] {
|
||||||
|
--callout-color: 120, 82, 238;
|
||||||
|
}
|
||||||
.callout[data-callout="question"], .callout[data-callout="help"], .callout[data-callout="faq"] {
|
.callout[data-callout="question"], .callout[data-callout="help"], .callout[data-callout="faq"] {
|
||||||
--callout-color: 236, 117, 0;
|
--callout-color: 236, 117, 0;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +75,9 @@ th {
|
||||||
.callout[data-callout="tip"] {
|
.callout[data-callout="tip"] {
|
||||||
--callout-color: 0, 191, 188;
|
--callout-color: 0, 191, 188;
|
||||||
}
|
}
|
||||||
|
.callout[data-callout="todo"] {
|
||||||
|
--callout-color: 8, 109, 221;
|
||||||
|
}
|
||||||
.callout-title {
|
.callout-title {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user