Ejemplo n.º 1
0
 def _parse_action(s: str, l: int, toks: "list[list[str]]"):
     if len(toks) > 1:
         raise ValueError("Assumption violated. Investigate.")
     if any(not isinstance(s, str) for s in toks[0]):
         raise ValueError("Unexpected shortcode nesting.")
     is_closing_tag = toks[0][0] == "/"
     content = toks[0][1:] if is_closing_tag else toks[0]
     name = content[0]
     args = [
         self.hugo_unescape_shortcode_arg(s) for s in content[1:]
     ]
     shortcode = ShortcodeTag(name,
                              args,
                              percent_delimiters,
                              closer=is_closing_tag)
     return ParseResults.from_dict({"shortcode": shortcode})
Ejemplo n.º 2
0
        def parse_action(_s, _l, toks):
            token = toks
            is_image = token.is_image
            title = token.title
            text = token.text
            destination = token.destination

            # Use self.scan_string not grammar.scan_string
            # so that parse actions attached to LinkParser fire for the nested
            # links, which seems desirable.
            text_links = tuple(self.scan_string(text))

            link = MarkdownLink(
                text=text,
                destination=destination,
                title=title,
                is_image=is_image,
                text_links=text_links,
            )

            return ParseResults.from_dict({"link": link})
Ejemplo n.º 3
0
 def _original_text_for(s: str, _l: int, toks):
     original_text = s[toks.pop("_original_start"):toks.pop("_original_end"
                                                            )]
     results = toks.asDict()
     results["original_text"] = original_text
     return ParseResults.from_dict(results)