mirror of
https://github.com/boostorg/docca.git
synced 2026-01-19 04:12:08 +00:00
add support for em- and en-dashes
This commit is contained in:
25
docca.py
25
docca.py
@@ -108,6 +108,27 @@ class UrlLink(Phrase):
|
||||
result = self.url
|
||||
return result
|
||||
|
||||
class EmDash:
|
||||
def __init__(self, *args, **kw):
|
||||
pass
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return '\u2014'
|
||||
|
||||
def __len__(self):
|
||||
return 0
|
||||
|
||||
class EnDash:
|
||||
def __init__(self, *args, **kw):
|
||||
pass
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return '\u2013'
|
||||
|
||||
def __len__(self):
|
||||
return 0
|
||||
|
||||
class Block:
|
||||
pass
|
||||
@@ -453,6 +474,8 @@ def make_phrase(element, index, allow_missing_refs=False):
|
||||
'ulink': make_url_link,
|
||||
'linebreak': make_linebreak,
|
||||
'ref': make_entity_reference,
|
||||
'mdash': EmDash,
|
||||
'ndash': EnDash,
|
||||
}[element.tag]
|
||||
return func(element, index, allow_missing_refs=allow_missing_refs)
|
||||
|
||||
@@ -1316,6 +1339,8 @@ def construct_environment(loader, config):
|
||||
env.tests['Monospaced'] = lambda x: isinstance(x, Monospaced)
|
||||
env.tests['EntityRef'] = lambda x: isinstance(x, EntityRef)
|
||||
env.tests['UrlLink'] = lambda x: isinstance(x, UrlLink)
|
||||
env.tests['EmDash'] = lambda x: isinstance(x, EmDash)
|
||||
env.tests['EnDash'] = lambda x: isinstance(x, EnDash)
|
||||
|
||||
env.tests['Block'] = lambda x: isinstance(x, Block)
|
||||
env.tests['Paragraph'] = lambda x: isinstance(x, Paragraph)
|
||||
|
||||
@@ -84,6 +84,14 @@ class EntityRef(Phrase): # text with associated entity
|
||||
class UrlLink(Phrase): # a direct full or relative link, similar to HTML <a>
|
||||
url -> str
|
||||
|
||||
class EmDash(Phrase): # an em-dash
|
||||
text -> str # the Unicode character for em-dashes
|
||||
def __len__(self) -> int # always 0
|
||||
|
||||
class EnDash(Phrase): # an en-dash
|
||||
text -> str # the Unicode character for en-dashes
|
||||
def __len__(self) -> int # always 0
|
||||
|
||||
class Block(): # A single block or hierarchy of blocks
|
||||
pass
|
||||
|
||||
|
||||
@@ -673,6 +673,10 @@ Convenience header {{ source_header(Config.convenience_header) }}
|
||||
{% macro phrase_part(part, in_code=False) -%}
|
||||
{%- if part is string -%}
|
||||
{{ text_helper(part, in_code=in_code) }}
|
||||
{%- elif part is EmDash -%}
|
||||
{{ part.text }}
|
||||
{%- elif part is EnDash -%}
|
||||
{{ part.text }}
|
||||
{%- elif part is Monospaced -%}
|
||||
`{{ phrase(part, in_code=True) }}`
|
||||
{%- elif part is Emphasised -%}
|
||||
|
||||
@@ -594,9 +594,11 @@ def test_phrase(entities, cfg, render):
|
||||
docca.Emphasised(['emph ', docca.Strong(['bold'])]),
|
||||
docca.Linebreak(),
|
||||
docca.UrlLink('http://a.b/c', ['link text']),
|
||||
docca.EmDash(),
|
||||
docca.EntityRef(entities['g1'], ['ref text']),
|
||||
docca.Linebreak(),
|
||||
docca.EntityRef(entities['ostream'], ['output stream']),
|
||||
docca.EnDash(),
|
||||
docca.Phrase([' ', 'more text']),
|
||||
docca.Linebreak(),
|
||||
docca.EntityRef(entities['o[]'], 'operator[]'),
|
||||
@@ -604,9 +606,9 @@ def test_phrase(entities, cfg, render):
|
||||
assert render(parts) == textwrap.dedent('''\
|
||||
regular text `monospaced text` ['emph [*bold]]
|
||||
|
||||
[@http://a.b/c link text][link ns1__ns2__klass.g `ref text`]
|
||||
[@http://a.b/c link text]\u2014[link ns1__ns2__klass.g `ref text`]
|
||||
|
||||
[@http://ostream.org `output stream`] more text
|
||||
[@http://ostream.org `output stream`]\u2013 more text
|
||||
|
||||
[link ns1__ns2__klass.operator__lb__rb_ `operator[]`]''')
|
||||
|
||||
@@ -616,9 +618,9 @@ def test_phrase(entities, cfg, render):
|
||||
assert render(parts) == textwrap.dedent('''\
|
||||
regular text `monospaced text` ['emph [*bold]]
|
||||
|
||||
[@http://a.b/c link text]``[link ns1__ns2__klass.g [^ns1::ns2::klass::g]]``
|
||||
[@http://a.b/c link text]\u2014``[link ns1__ns2__klass.g [^ns1::ns2::klass::g]]``
|
||||
|
||||
``[@http://ostream.org [^std::ostream]]`` more text
|
||||
``[@http://ostream.org [^std::ostream]]``\u2013 more text
|
||||
|
||||
``[link ns1__ns2__klass.operator__lb__rb_ [^ns1::ns2::klass::operator\[\]]]``''')
|
||||
|
||||
|
||||
@@ -517,6 +517,14 @@ def test_phrases():
|
||||
assert isinstance(p[0], docca.Phrase)
|
||||
assert p[0].text == ''
|
||||
|
||||
p = docca.make_phrase(make_elem({'tag': 'mdash'}), None)
|
||||
assert isinstance(p, docca.EmDash)
|
||||
assert p.text == '\u2014'
|
||||
|
||||
p = docca.make_phrase(make_elem({'tag': 'ndash'}), None)
|
||||
assert isinstance(p, docca.EnDash)
|
||||
assert p.text == '\u2013'
|
||||
|
||||
def test_namespace():
|
||||
ns = docca.Namespace(
|
||||
make_elem({
|
||||
|
||||
Reference in New Issue
Block a user