# HG changeset patch # User Paul Boddie # Date 1670799482 -3600 # Node ID 7a05ff0ee28dd011df882d95e817f10fa491b145 # Parent 171156732536d47db20722427dc2ffe20a33df2e Added non-breaking space syntax. diff -r 171156732536 -r 7a05ff0ee28d moinformat/parsers/moin.py --- a/moinformat/parsers/moin.py Fri Jun 03 21:54:37 2022 +0200 +++ b/moinformat/parsers/moin.py Sun Dec 11 23:58:02 2022 +0100 @@ -3,7 +3,7 @@ """ Moin wiki format parser. -Copyright (C) 2017, 2018, 2019, 2020 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2020, 2022 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -38,11 +38,11 @@ from moinformat.tree.moin import Anchor, Break, Comment, DefItem, DefTerm, \ Directive, FontStyle, Heading, Larger, \ LineBreak, Link, LinkLabel, LinkParameter, \ - List, ListItem, Macro, Monospace, Region, \ - Rule, Smaller, Strikethrough, Subscript, \ - Superscript, Table, TableAttr, TableAttrs, \ - TableCell, TableRow, Text, Transclusion, \ - Underline, Verbatim + List, ListItem, Macro, Monospace, \ + NonBreakingSpace, Region, Rule, Smaller, \ + Strikethrough, Subscript, Superscript, Table, \ + TableAttr, TableAttrs, TableCell, TableRow, \ + Text, Transclusion, Underline, Verbatim # Link parsing. @@ -648,6 +648,9 @@ self.root.macros.append(macro) + def parse_nbsp(self, region): + region.append_inline(NonBreakingSpace()) + def parse_verbatim(self, region): text = self.match_group("verbatim") region.append_inline(Verbatim(text)) @@ -828,6 +831,8 @@ r"\)"))), # ) (optional) ">>")), # >> + "nbsp" : r"\\_", # \_ + "verbatim" : join(("<<<", # <<< group("verbatim", r"\P*?"), # ... ">>>")), @@ -924,7 +929,7 @@ inline_without_links_pattern_names = [ "anchor", "fontstyle", "larger", "linebreak", "macro", - "monospace", "regionstart", "smaller", "strike", "sub", "super", + "monospace", "nbsp", "regionstart", "smaller", "strike", "sub", "super", "underline", "verbatim" ] @@ -989,6 +994,7 @@ "linkend" : end_region, "linksep" : end_region, "macro" : parse_macro, + "nbsp" : parse_nbsp, "listitemend" : end_region, "listitem" : parse_listitem, "listitem_alpha" : parse_listitem, diff -r 171156732536 -r 7a05ff0ee28d moinformat/serialisers/html/moin.py --- a/moinformat/serialisers/html/moin.py Fri Jun 03 21:54:37 2022 +0200 +++ b/moinformat/serialisers/html/moin.py Sun Dec 11 23:58:02 2022 +0100 @@ -331,6 +331,9 @@ key, value = key_value self.out("%s='%s'" % (key, escape_attr(value))) + def nbsp(self): + self.out(" ") + def rule(self, height): self.out("
" % min(height, 10)) diff -r 171156732536 -r 7a05ff0ee28d moinformat/serialisers/moin/moin.py --- a/moinformat/serialisers/moin/moin.py Fri Jun 03 21:54:37 2022 +0200 +++ b/moinformat/serialisers/moin/moin.py Sun Dec 11 23:58:02 2022 +0100 @@ -211,6 +211,9 @@ else: self.out("=".join(key_value)) + def nbsp(self): + self.out(r"\_") + def rule(self, height): self.out("-" * (height + 4)) diff -r 171156732536 -r 7a05ff0ee28d moinformat/tree/moin.py --- a/moinformat/tree/moin.py Fri Jun 03 21:54:37 2022 +0200 +++ b/moinformat/tree/moin.py Sun Dec 11 23:58:02 2022 +0100 @@ -3,7 +3,7 @@ """ Moin wiki format document tree nodes. -Copyright (C) 2017, 2018, 2019, 2020, 2021 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -778,6 +778,19 @@ def to_string(self, out): out.linebreak() +class NonBreakingSpace(Node): + + "A non-breaking space within a block." + + def __repr__(self): + return "NonBreakingSpace()" + + def prettyprint(self, indent=""): + return "%sNonBreakingSpace" % indent + + def to_string(self, out): + out.nbsp() + class Rule(Node): "A horizontal rule."