diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2019-07-06 00:34:19 -0500 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2019-07-06 00:34:19 -0500 |
commit | ffee388a149836b1f8d128bc953c1b0363cee82b (patch) | |
tree | 8811ad21cdb6b09c0aecc42328ebd2b6f45341f0 /examples | |
parent | 8b73519b483f155cfee69e36357833310ffe9dd6 (diff) | |
download | pyparsing-git-ffee388a149836b1f8d128bc953c1b0363cee82b.tar.gz |
Add support for multiple '...' skips in a single expression; `_skippped` results name will always return a list of skipped items
Diffstat (limited to 'examples')
-rw-r--r-- | examples/nested_markup.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/nested_markup.py b/examples/nested_markup.py index 40267e6..6d83636 100644 --- a/examples/nested_markup.py +++ b/examples/nested_markup.py @@ -27,11 +27,12 @@ bolded = ('bold' + markup_body).setParseAction(convert_markup_to_html("<B>", "</ # another markup and parse action to parse links - again using transform string # to recursively parse any markup in the link text def convert_link_to_html(s, l, t): - t['link_text'] = wiki_markup.transformString(t['link_text']) + link_text, url = t._skipped + t['link_text'] = wiki_markup.transformString(link_text) + t['url'] = url return '<A href="{url}">{link_text}</A>'.format_map(t) -urlRef = ('link' - + '{' + pp.SkipTo('->')('link_text') + '->' + pp.SkipTo('}')('url') + '}' - ).setParseAction(convert_link_to_html) + +urlRef = (pp.Keyword('link') + '{' + ... + '->' + ... + '}').setParseAction(convert_link_to_html) # now inject all the markup bits as possible markup expressions wiki_markup <<= urlRef | italicized | bolded |