Compare commits
No commits in common. "743896b4b2a4c1d811d3654e522001ba5152f9af" and "b20313fe4bc5def28d809f2331f45a0a28d6ec4d" have entirely different histories.
743896b4b2
...
b20313fe4b
@ -13,7 +13,7 @@ from urllib.parse import urlparse
|
||||
|
||||
import markdown
|
||||
from markdown import Markdown
|
||||
from markdown.blockprocessors import BlockProcessor, BlockParser, BlockQuoteProcessor
|
||||
from markdown.blockprocessors import BlockProcessor, BlockParser
|
||||
from markdown.extensions import Extension
|
||||
from markdown.extensions.footnotes import (FootnoteExtension, FootnoteBlockProcessor, FootnoteInlineProcessor,
|
||||
FootnoteTreeprocessor, FootnotePostTreeprocessor, FootnotePostprocessor)
|
||||
@ -861,71 +861,6 @@ class ObsidianStyleFootnotes(FootnoteExtension):
|
||||
md.postprocessors.register(FootnotePostprocessor(self), 'footnote', 25)
|
||||
|
||||
|
||||
class ObsidianStyleBlockquotes(Extension):
|
||||
|
||||
class ObsidianBlockQuote(BlockQuoteProcessor):
|
||||
CALLOUT = re.compile(r'^\[!([a-z]+)\]([-+])?(?:[ ]+(.*))?')
|
||||
|
||||
def normal_blockquote(self, parent: etree.Element, block: str) -> None:
|
||||
sibling = self.lastChild(parent)
|
||||
if sibling is not None and sibling.tag == "blockquote":
|
||||
# Previous block was a blockquote so set that as this blocks parent
|
||||
quote = sibling
|
||||
else:
|
||||
# This is a new blockquote. Create a new parent element.
|
||||
quote = etree.SubElement(parent, 'blockquote')
|
||||
# Recursively parse block with blockquote as parent.
|
||||
# change parser state so blockquotes embedded in lists use `p` tags
|
||||
self.parser.state.set('blockquote')
|
||||
self.parser.parseChunk(quote, block)
|
||||
self.parser.state.reset()
|
||||
|
||||
def callout_block(self, parent: etree.Element, lines: list[str]) -> None:
|
||||
m = self.CALLOUT.match(lines[0])
|
||||
callout_type = m.group(1)
|
||||
# folding = m.group(2)
|
||||
title = m.group(3)
|
||||
if not title:
|
||||
title = callout_type.title()
|
||||
base_div = etree.SubElement(parent, 'div', {'class': 'callout', 'data-callout': callout_type})
|
||||
title_div = etree.SubElement(base_div, 'div', {'class': 'callout-title'})
|
||||
# TODO: add title icon here
|
||||
inner_title_div = etree.SubElement(title_div, 'div', {'class': 'callout-title-inner'})
|
||||
inner_title_div.text = title
|
||||
content_div = etree.SubElement(base_div, 'div', {'class': 'callout-content'})
|
||||
lines.pop(0)
|
||||
first = True
|
||||
for line in lines:
|
||||
if first:
|
||||
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:
|
||||
block = blocks.pop(0)
|
||||
lines: list[str] = []
|
||||
callout = False
|
||||
m = self.RE.search(block)
|
||||
if m:
|
||||
before = block[:m.start()] # Lines before blockquote
|
||||
# Pass lines before blockquote in recursively for parsing first.
|
||||
self.parser.parseBlocks(parent, [before])
|
||||
# Remove `> ` from beginning of each line.
|
||||
lines = [self.clean(line) for line in block[m.start():].split('\n')]
|
||||
callout = (self.CALLOUT.match(lines[0]) is not None)
|
||||
block = '\n'.join(lines)
|
||||
if callout:
|
||||
self.callout_block(parent, lines)
|
||||
else:
|
||||
self.normal_blockquote(parent, block)
|
||||
|
||||
def extendMarkdown(self, md) -> None:
|
||||
md.parser.blockprocessors.register(ObsidianStyleBlockquotes.ObsidianBlockQuote(md.parser), 'quote', 20)
|
||||
|
||||
|
||||
def create_markdown_parser(context: Context) -> markdown.Markdown:
|
||||
"""
|
||||
Creates a Markdown parser with all our extensions loaded.
|
||||
@ -952,7 +887,6 @@ def create_markdown_parser(context: Context) -> markdown.Markdown:
|
||||
MetaStripper(),
|
||||
ObsidianComments(),
|
||||
ObsidianStyleFootnotes(SUPERSCRIPT_TEXT='[{}]', SEPARATOR='-'),
|
||||
ObsidianStyleBlockquotes(),
|
||||
ObsidianImages(context),
|
||||
ObsidianLinks(context),
|
||||
ObsidianLists(),
|
||||
|
@ -50,42 +50,6 @@ td {
|
||||
th {
|
||||
border: 1px solid #e0e0e0;
|
||||
}
|
||||
.callout {
|
||||
--callout-color: 8, 109, 221;
|
||||
--callout-icon: lucide-pencil;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
border-style: solid;
|
||||
border-color: rgba(var(--callout-color), 0.25);
|
||||
border-width: 0px;
|
||||
border-radius: 4px;
|
||||
margin: 1em 0;
|
||||
mix-blend-mode: darken;
|
||||
background-color: rgba(var(--callout-color), 0.1);
|
||||
padding: 12px 12px 12px 24px;
|
||||
}
|
||||
.callout[data-callout="info"] {
|
||||
--callout-color: 8, 109, 221;
|
||||
--callout-icon: lucide-info;
|
||||
}
|
||||
.callout[data-callout="tip"] {
|
||||
--callout-color: 0, 191, 188;
|
||||
--callout-icon: lucide-flame;
|
||||
}
|
||||
.callout-title {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
font-size: inherit;
|
||||
color: rgb(var(--callout-color));
|
||||
line-height: 1.3;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
.callout-title-inner {
|
||||
font-weight: 600;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* Following are styles generated by Pygments "tango" style */
|
||||
pre { line-height: 125%; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user