Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for MD block quotes with attribution(s) #759

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions breathe/parser/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,21 @@ def buildChildren(self, child_, nodeName_):
self.text += child_.nodeValue


class docBlockQuoteTypeSub(supermod.docBlockQuoteType):

node_type = "docblockquote"

def __init__(self, para=None):
supermod.docBlockQuoteType.__init__(self, para)

def buildChildren(self, child_, nodeName_):
supermod.docBlockQuoteType.buildChildren(self, child_, nodeName_)


supermod.docBlockQuoteType.subclass = docBlockQuoteTypeSub
# end class docBlockQuoteTypeSub


class docParaTypeSub(supermod.docParaType):

node_type = "docpara"
Expand Down Expand Up @@ -1068,6 +1083,10 @@ def buildChildren(self, child_, nodeName_):
obj_ = supermod.docParBlockType.factory()
obj_.build(child_)
self.content.append(obj_)
elif child_.nodeType == Node.ELEMENT_NODE and nodeName_ == "blockquote":
obj_ = supermod.docBlockQuoteType.factory()
obj_.build(child_)
self.content.append(obj_)
elif child_.nodeType == Node.ELEMENT_NODE and nodeName_ == "table":
obj_ = supermod.docTableType.factory()
obj_.build(child_)
Expand All @@ -1080,6 +1099,14 @@ def buildChildren(self, child_, nodeName_):
obj_ = supermod.docDotType.factory()
obj_.build(child_)
self.content.append(obj_)
elif child_.nodeType == Node.ELEMENT_NODE and (
nodeName_ == "ndash" or nodeName_ == "mdash"
):
# inject a emphasized dash unicode char as a placeholder/flag for rendering
# later. See visit_docblockquote()
obj_ = self.mixedclass_(MixedContainer.CategoryText,
MixedContainer.TypeText, "", "—")
self.content.append(obj_)
else:
obj_ = None

Expand Down
65 changes: 65 additions & 0 deletions breathe/parser/compoundsuper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5803,6 +5803,71 @@ def buildChildren(self, child_, nodeName_):
# end class docCharType


class docBlockQuoteType(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, mixedclass_=None, para=None):
if mixedclass_ is None:
self.mixedclass_ = MixedContainer
else:
self.mixedclass_ = mixedclass_
if para is None:
self.para = []
else:
self.para = para
def factory(*args_, **kwargs_):
if docBlockQuoteType.subclass:
return docBlockQuoteType.subclass(*args_, **kwargs_)
else:
return docBlockQuoteType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_para(self): return self.para
def set_para(self, para): self.para = para
def add_para(self, value): self.para.append(value)
def insert_para(self, index, value): self.para[index] = value
def export(self, outfile, level, namespace_='', name_='docBlockQuoteType', namespacedef_=''):
showIndent(outfile, level)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
self.exportAttributes(outfile, level, namespace_, name_='docBlockQuoteType')
if self.hasContent_():
outfile.write('>\n')
self.exportChildren(outfile, level + 1, namespace_, name_)
showIndent(outfile, level)
outfile.write('</%s%s>\n' % (namespace_, name_))
else:
outfile.write('/>\n')
def exportAttributes(self, outfile, level, namespace_='', name_='docBlockQuoteType'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='docBlockQuoteType'):
for para_ in self.para:
para_.export(outfile, level, namespace_, name_='para')
def hasContent_(self):
if (
self.para
):
return True
else:
return False
def build(self, node_):
attrs = node_.attributes
self.buildAttributes(attrs)
self.valueOf_ = ''
for child_ in node_.childNodes:
nodeName_ = child_.nodeName.split(':')[-1]
self.buildChildren(child_, nodeName_)
def buildAttributes(self, attrs):
pass
def buildChildren(self, child_, nodeName_):
if child_.nodeType == Node.ELEMENT_NODE and \
nodeName_ == 'para':
obj_ = docParaType.factory()
obj_.build(child_)
obj_ = self.mixedclass_(MixedContainer.CategoryComplex,
MixedContainer.TypeNone, 'para', obj_)
self.para.append(obj_)
# end class docBlockQuoteType


class docParBlockType(GeneratedsSuper):
subclass = None
superclass = None
Expand Down
12 changes: 12 additions & 0 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,17 @@ def visit_docpara(self, node) -> List[Node]:
def visit_docparblock(self, node) -> List[Node]:
return self.render_iterable(node.para)

def visit_docblockquote(self, node) -> List[Node]:
nodelist = self.render_iterable(node.para)
# catch block quote attributions here; the <ndash/> tag is the only identifier,
# and it is nested within a subsequent <para> tag
if nodelist and nodelist[-1].astext().startswith("&#8212;"):
# nodes.attribution prepends the author with an emphasized dash.
# replace the &#8212; placeholder and strip any leading whitespace.
text = nodelist[-1].astext().replace("&#8212;", "").lstrip()
nodelist[-1] = nodes.attribution("", text)
return [nodes.block_quote("", classes=[], *nodelist)]

def visit_docimage(self, node) -> List[Node]:
"""Output docutils image node using name attribute from xml as the uri"""

Expand Down Expand Up @@ -2527,6 +2538,7 @@ def dispatch_memberdef(self, node) -> List[Node]:
"docdotfile": visit_docdotfile,
"docdot": visit_docdot,
"graph": visit_docgraph,
"docblockquote": visit_docblockquote,
}

def render_string(self, node: str) -> List[Node]:
Expand Down