diff options
| author | Waylan Limberg <waylan.limberg@icloud.com> | 2023-04-06 19:21:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-06 19:21:46 -0400 |
| commit | 07b8b2c90a92c20fb0740d5527c6a219d2afb7ae (patch) | |
| tree | 5f8058c02c96082ca21072698fc46a09e7c36a20 /markdown/extensions | |
| parent | be1c2839dd587a858f91c710e56667cba9f5329d (diff) | |
| download | python-markdown-07b8b2c90a92c20fb0740d5527c6a219d2afb7ae.tar.gz | |
Use pyspelling to check spelling.
In addition to checking the spelling in our documentation, we are now also checking the spelling of the README.md and similar files as well as comments in our Python code.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/__init__.py | 10 | ||||
| -rw-r--r-- | markdown/extensions/abbr.py | 6 | ||||
| -rw-r--r-- | markdown/extensions/admonition.py | 6 | ||||
| -rw-r--r-- | markdown/extensions/attr_list.py | 22 | ||||
| -rw-r--r-- | markdown/extensions/codehilite.py | 48 | ||||
| -rw-r--r-- | markdown/extensions/def_list.py | 4 | ||||
| -rw-r--r-- | markdown/extensions/extra.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/fenced_code.py | 20 | ||||
| -rw-r--r-- | markdown/extensions/footnotes.py | 24 | ||||
| -rw-r--r-- | markdown/extensions/legacy_attrs.py | 4 | ||||
| -rw-r--r-- | markdown/extensions/legacy_em.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/md_in_html.py | 37 | ||||
| -rw-r--r-- | markdown/extensions/meta.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/nl2br.py | 4 | ||||
| -rw-r--r-- | markdown/extensions/smarty.py | 8 | ||||
| -rw-r--r-- | markdown/extensions/tables.py | 2 | ||||
| -rw-r--r-- | markdown/extensions/toc.py | 23 | ||||
| -rw-r--r-- | markdown/extensions/wikilinks.py | 4 |
18 files changed, 112 insertions, 116 deletions
diff --git a/markdown/extensions/__init__.py b/markdown/extensions/__init__.py index 2d8d72a..7a32e1c 100644 --- a/markdown/extensions/__init__.py +++ b/markdown/extensions/__init__.py @@ -25,12 +25,12 @@ from ..util import parseBoolValue class Extension: """ Base class for extensions to subclass. """ - # Default config -- to be overridden by a subclass + # Default configuration -- to be overridden by a subclass # Must be of the following format: # { # 'key': ['value', 'description'] # } - # Note that Extension.setConfig will raise a KeyError + # Note that `Extension.setConfig` will raise a `KeyError` # if a default is not set here. config = {} @@ -50,11 +50,11 @@ class Extension: return {key: self.getConfig(key) for key in self.config.keys()} def getConfigInfo(self): - """ Return all config descriptions as a list of tuples. """ + """ Return all `config` descriptions as a list of tuples. """ return [(key, self.config[key][1]) for key in self.config.keys()] def setConfig(self, key, value): - """ Set a config setting for `key` with the given `value`. """ + """ Set a `config` setting for `key` with the given `value`. """ if isinstance(self.config[key][0], bool): value = parseBoolValue(value) if self.config[key][0] is None: @@ -62,7 +62,7 @@ class Extension: self.config[key][0] = value def setConfigs(self, items): - """ Set multiple config settings given a dict or list of tuples. """ + """ Set multiple `config` settings given a dict or list of tuples. """ if hasattr(items, 'items'): # it's a dict items = items.items() diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py index 9879314..0649870 100644 --- a/markdown/extensions/abbr.py +++ b/markdown/extensions/abbr.py @@ -7,7 +7,7 @@ This extension adds abbreviation handling to Python-Markdown. See <https://Python-Markdown.github.io/extensions/abbreviations> for documentation. -Oringinal code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/) and +Original code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/) and [Seemant Kulleen](http://www.kulleen.org/) All changes Copyright 2008-2014 The Python Markdown Project @@ -28,7 +28,7 @@ class AbbrExtension(Extension): """ Abbreviation Extension for Python-Markdown. """ def extendMarkdown(self, md): - """ Insert AbbrPreprocessor before ReferencePreprocessor. """ + """ Insert `AbbrPreprocessor` before `ReferencePreprocessor`. """ md.parser.blockprocessors.register(AbbrPreprocessor(md.parser), 'abbr', 16) @@ -43,7 +43,7 @@ class AbbrPreprocessor(BlockProcessor): def run(self, parent, blocks): ''' Find and remove all Abbreviation references from the text. - Each reference is set as a new AbbrPattern in the markdown instance. + Each reference is set as a new `AbbrPattern` in the markdown instance. ''' block = blocks.pop(0) diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index cb8d901..25bb19e 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -4,7 +4,7 @@ Admonition extension for Python-Markdown Adds rST-style admonitions. Inspired by [rST][] feature with the same name. -[rST]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions # noqa +[rST]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions See <https://Python-Markdown.github.io/extensions/admonition> for documentation. @@ -82,7 +82,7 @@ class AdmonitionProcessor(BlockProcessor): last_child and last_child.tag in ('ul', 'ol', 'dl') ): - # The expectation is that we'll find an <li> or <dt>. + # The expectation is that we'll find an `<li>` or `<dt>`. # We should get its last child as well. sibling = self.lastChild(last_child) last_child = self.lastChild(sibling) if sibling else None @@ -155,7 +155,7 @@ class AdmonitionProcessor(BlockProcessor): klass, title = match.group(1).lower(), match.group(2) klass = self.RE_SPACES.sub(' ', klass) if title is None: - # no title was provided, use the capitalized classname as title + # no title was provided, use the capitalized class name as title # e.g.: `!!! note` will render # `<p class="admonition-title">Note</p>` title = klass.split(' ', 1)[0].capitalize() diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py index 9a67551..bc06786 100644 --- a/markdown/extensions/attr_list.py +++ b/markdown/extensions/attr_list.py @@ -3,7 +3,7 @@ Attribute List Extension for Python-Markdown ============================================ Adds attribute list syntax. Inspired by -[maruku](http://maruku.rubyforge.org/proposal.html#attribute_lists)'s +[Maruku](http://maruku.rubyforge.org/proposal.html#attribute_lists)'s feature of the same name. See <https://Python-Markdown.github.io/extensions/attr_list> @@ -77,33 +77,33 @@ class AttrListTreeprocessor(Treeprocessor): def run(self, doc): for elem in doc.iter(): if self.md.is_block_level(elem.tag): - # Block level: check for attrs on last line of text + # Block level: check for `attrs` on last line of text RE = self.BLOCK_RE if isheader(elem) or elem.tag in ['dt', 'td', 'th']: - # header, def-term, or table cell: check for attrs at end of element + # header, def-term, or table cell: check for attributes at end of element RE = self.HEADER_RE if len(elem) and elem.tag == 'li': - # special case list items. children may include a ul or ol. + # special case list items. children may include a `ul` or `ol`. pos = None - # find the ul or ol position + # find the `ul` or `ol` position for i, child in enumerate(elem): if child.tag in ['ul', 'ol']: pos = i break if pos is None and elem[-1].tail: - # use tail of last child. no ul or ol. + # use tail of last child. no `ul` or `ol`. m = RE.search(elem[-1].tail) if m: self.assign_attrs(elem, m.group(1)) elem[-1].tail = elem[-1].tail[:m.start()] elif pos is not None and pos > 0 and elem[pos-1].tail: - # use tail of last child before ul or ol + # use tail of last child before `ul` or `ol` m = RE.search(elem[pos-1].tail) if m: self.assign_attrs(elem, m.group(1)) elem[pos-1].tail = elem[pos-1].tail[:m.start()] elif elem.text: - # use text. ul is first child. + # use text. `ul` is first child. m = RE.search(elem.text) if m: self.assign_attrs(elem, m.group(1)) @@ -127,7 +127,7 @@ class AttrListTreeprocessor(Treeprocessor): # clean up trailing #s elem.text = elem.text.rstrip('#').rstrip() else: - # inline: check for attrs at start of tail + # inline: check for `attrs` at start of tail if elem.tail: m = self.INLINE_RE.match(elem.tail) if m: @@ -135,7 +135,7 @@ class AttrListTreeprocessor(Treeprocessor): elem.tail = elem.tail[m.end():] def assign_attrs(self, elem, attrs): - """ Assign attrs to element. """ + """ Assign `attrs` to element. """ for k, v in get_attrs(attrs): if k == '.': # add to class @@ -145,7 +145,7 @@ class AttrListTreeprocessor(Treeprocessor): else: elem.set('class', v) else: - # assign attr k with v + # assign attribute `k` with `v` elem.set(self.sanitize_name(k), v) def sanitize_name(self, name): diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index 00445ec..1941ce2 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -54,24 +54,24 @@ class CodeHilite: html = code.hilite() Arguments: - * src: Source string or any object with a .readline attribute. + * `src`: Source string or any object with a `.readline` attribute. - * lang: String name of Pygments lexer to use for highlighting. Default: `None`. + * `lang`: String name of Pygments lexer to use for highlighting. Default: `None`. - * guess_lang: Auto-detect which lexer to use. Ignored if `lang` is set to a valid + * `guess_lang`: Auto-detect which lexer to use. Ignored if `lang` is set to a valid value. Default: `True`. - * use_pygments: Pass code to pygments for code highlighting. If `False`, the code is + * `use_pygments`: Pass code to Pygments for code highlighting. If `False`, the code is instead wrapped for highlighting by a JavaScript library. Default: `True`. - * pygments_formatter: The name of a Pygments formatter or a formatter class used for + * `pygments_formatter`: The name of a Pygments formatter or a formatter class used for highlighting the code blocks. Default: `html`. - * linenums: An alias to Pygments `linenos` formatter option. Default: `None`. + * `linenums`: An alias to Pygments `linenos` formatter option. Default: `None`. - * css_class: An alias to Pygments `cssclass` formatter option. Default: 'codehilite'. + * `css_class`: An alias to Pygments `cssclass` formatter option. Default: 'codehilite'. - * lang_prefix: Prefix prepended to the language. Default: "language-". + * `lang_prefix`: Prefix prepended to the language. Default: "language-". Other Options: Any other options are accepted and passed on to the lexer and formatter. Therefore, @@ -85,7 +85,7 @@ class CodeHilite: Additionally, when Pygments is enabled, the code's language is passed to the formatter as an extra option `lang_str`, whose value being `{lang_prefix}{lang}`. - This option has no effect to the Pygments's builtin formatters. + This option has no effect to the Pygments' builtin formatters. Advanced Usage: code = CodeHilite( @@ -113,7 +113,7 @@ class CodeHilite: if 'cssclass' not in options: options['cssclass'] = options.pop('css_class', 'codehilite') if 'wrapcode' not in options: - # Override pygments default + # Override Pygments default options['wrapcode'] = True # Disallow use of `full` option options['full'] = False @@ -122,10 +122,10 @@ class CodeHilite: def hilite(self, shebang=True): """ - Pass code to the [Pygments](https://pygments.org/) highliter with - optional line numbers. The output should then be styled with css to + Pass code to the [Pygments](https://pygments.org/) highlighter with + optional line numbers. The output should then be styled with CSS to your liking. No styles are applied by default - only styling hooks - (i.e.: <span class="k">). + (i.e.: `<span class="k">`). returns : A string of html. @@ -160,7 +160,7 @@ class CodeHilite: formatter = self.pygments_formatter(lang_str=lang_str, **self.options) return highlight(self.src, lexer, formatter) else: - # just escape and build markup usable by JS highlighting libs + # just escape and build markup usable by JavaScript highlighting libraries txt = self.src.replace('&', '&') txt = txt.replace('<', '<') txt = txt.replace('>', '>') @@ -185,11 +185,11 @@ class CodeHilite: said line should be removed or left in place. If the shebang line contains a path (even a single /) then it is assumed to be a real shebang line and left alone. However, if no path is given - (e.i.: #!python or :::python) then it is assumed to be a mock shebang + (e.i.: `#!python` or `:::python`) then it is assumed to be a mock shebang for language identification of a code fragment and removed from the code block prior to processing for code highlighting. When a mock - shebang (e.i: #!python) is found, line numbering is turned on. When - colons are found in place of a shebang (e.i.: :::python), line + shebang (e.i: `#!python`) is found, line numbering is turned on. When + colons are found in place of a shebang (e.i.: `:::python`), line numbering is left in the current state - off by default. Also parses optional list of highlight lines, like: @@ -251,7 +251,7 @@ class HiliteTreeprocessor(Treeprocessor): return text def run(self, root): - """ Find code blocks and store in htmlStash. """ + """ Find code blocks and store in `htmlStash`. """ blocks = root.iter('pre') for block in blocks: if len(block) == 1 and block[0].tag == 'code': @@ -263,16 +263,16 @@ class HiliteTreeprocessor(Treeprocessor): **local_config ) placeholder = self.md.htmlStash.store(code.hilite()) - # Clear codeblock in etree instance + # Clear code block in `etree` instance block.clear() - # Change to p element which will later + # Change to `p` element which will later # be removed when inserting raw html block.tag = 'p' block.text = placeholder class CodeHiliteExtension(Extension): - """ Add source code highlighting to markdown codeblocks. """ + """ Add source code highlighting to markdown code blocks. """ def __init__(self, **kwargs): # define default configs @@ -311,14 +311,14 @@ class CodeHiliteExtension(Extension): # manually set unknown keywords. if isinstance(value, str): try: - # Attempt to parse str as a bool value + # Attempt to parse `str` as a boolean value value = parseBoolValue(value, preserve_none=True) except ValueError: - pass # Assume it's not a bool value. Use as-is. + pass # Assume it's not a boolean value. Use as-is. self.config[key] = [value, ''] def extendMarkdown(self, md): - """ Add HilitePostprocessor to Markdown instance. """ + """ Add `HilitePostprocessor` to Markdown instance. """ hiliter = HiliteTreeprocessor(md) hiliter.config = self.getConfigs() md.treeprocessors.register(hiliter, 'hilite', 30) diff --git a/markdown/extensions/def_list.py b/markdown/extensions/def_list.py index 17549f0..c2f23a6 100644 --- a/markdown/extensions/def_list.py +++ b/markdown/extensions/def_list.py @@ -92,7 +92,7 @@ class DefListIndentProcessor(ListIndentProcessor): LIST_TYPES = ['dl', 'ol', 'ul'] def create_item(self, parent, block): - """ Create a new dd or li (depending on parent) and parse the block with it as the parent. """ + """ Create a new `dd` or `li` (depending on parent) and parse the block with it as the parent. """ dd = etree.SubElement(parent, 'dd') self.parser.parseBlocks(dd, [block]) @@ -102,7 +102,7 @@ class DefListExtension(Extension): """ Add definition lists to Markdown. """ def extendMarkdown(self, md): - """ Add an instance of DefListProcessor to BlockParser. """ + """ Add an instance of `DefListProcessor` to `BlockParser`. """ md.parser.blockprocessors.register(DefListIndentProcessor(md.parser), 'defindent', 85) md.parser.blockprocessors.register(DefListProcessor(md.parser), 'deflist', 25) diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py index 909ba07..8f73806 100644 --- a/markdown/extensions/extra.py +++ b/markdown/extensions/extra.py @@ -46,7 +46,7 @@ class ExtraExtension(Extension): """ Add various extensions to Markdown class.""" def __init__(self, **kwargs): - """ config is a dumb holder which gets passed to actual ext later. """ + """ `config` is a dumb holder which gets passed to the actual extension later. """ self.config = kwargs def extendMarkdown(self, md): diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 409166a..a0874d2 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -34,7 +34,7 @@ class FencedCodeExtension(Extension): super().__init__(**kwargs) def extendMarkdown(self, md): - """ Add FencedBlockPreprocessor to the Markdown instance. """ + """ Add `FencedBlockPreprocessor` to the Markdown instance. """ md.registerExtension(self) md.preprocessors.register(FencedBlockPreprocessor(md, self.getConfigs()), 'fenced_code_block', 25) @@ -60,7 +60,7 @@ class FencedBlockPreprocessor(Preprocessor): self.checked_for_deps = False self.codehilite_conf = {} self.use_attr_list = False - # List of options to convert to bool values + # List of options to convert to boolean values self.bool_options = [ 'linenums', 'guess_lang', @@ -69,7 +69,7 @@ class FencedBlockPreprocessor(Preprocessor): ] def run(self, lines): - """ Match and store Fenced Code Blocks in the HtmlStash. """ + """ Match and store Fenced Code Blocks in the `HtmlStash`. """ # Check for dependent extensions if not self.checked_for_deps: @@ -94,16 +94,16 @@ class FencedBlockPreprocessor(Preprocessor): if m.group('lang'): lang = m.group('lang') if m.group('hl_lines'): - # Support hl_lines outside of attrs for backward-compatibility + # Support `hl_lines` outside of `attrs` for backward-compatibility config['hl_lines'] = parse_hl_lines(m.group('hl_lines')) - # If config is not empty, then the codehighlite extension + # If `config` is not empty, then the `codehighlite` extension # is enabled, so we call it to highlight the code if self.codehilite_conf and self.codehilite_conf['use_pygments'] and config.get('use_pygments', True): local_config = self.codehilite_conf.copy() local_config.update(config) - # Combine classes with cssclass. Ensure cssclass is at end - # as pygments appends a suffix under certain circumstances. + # Combine classes with `cssclass`. Ensure `cssclass` is at end + # as Pygments appends a suffix under certain circumstances. # Ignore ID as Pygments does not offer an option to set it. if classes: local_config['css_class'] = '{} {}'.format( @@ -128,9 +128,9 @@ class FencedBlockPreprocessor(Preprocessor): if id: id_attr = f' id="{_escape_attrib_html(id)}"' if self.use_attr_list and config and not config.get('use_pygments', False): - # Only assign key/value pairs to code element if attr_list ext is enabled, key/value pairs - # were defined on the code block, and the `use_pygments` key was not set to True. The - # `use_pygments` key could be either set to False or not defined. It is omitted from output. + # Only assign key/value pairs to code element if `attr_list` extension is enabled, key/value + # pairs were defined on the code block, and the `use_pygments` key was not set to `True`. The + # `use_pygments` key could be either set to `False` or not defined. It is omitted from output. kv_pairs = ''.join( f' {k}="{_escape_attrib_html(v)}"' for k, v in config.items() if k != 'use_pygments' ) diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index 8a2e3c5..41074c0 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -74,20 +74,20 @@ class FootnoteExtension(Extension): md.registerExtension(self) self.parser = md.parser self.md = md - # Insert a blockprocessor before ReferencePreprocessor + # Insert a `blockprocessor` before `ReferencePreprocessor` md.parser.blockprocessors.register(FootnoteBlockProcessor(self), 'footnote', 17) - # Insert an inline pattern before ImageReferencePattern + # Insert an inline pattern before `ImageReferencePattern` FOOTNOTE_RE = r'\[\^([^\]]*)\]' # blah blah [^1] blah md.inlinePatterns.register(FootnoteInlineProcessor(FOOTNOTE_RE, self), 'footnote', 175) # Insert a tree-processor that would actually add the footnote div - # This must be before all other treeprocessors (i.e., inline and - # codehilite) so they can run on the the contents of the div. + # This must be before all other tree-processors (i.e., `inline` and + # `codehilite`) so they can run on the the contents of the div. md.treeprocessors.register(FootnoteTreeprocessor(self), 'footnote', 50) # Insert a tree-processor that will run after inline is done. # In this tree-processor we want to check our duplicate footnote tracker - # And add additional backrefs to the footnote pointing back to the + # And add additional `backrefs` to the footnote pointing back to the # duplicated references. md.treeprocessors.register(FootnotePostTreeprocessor(self), 'footnote-duplicate', 15) @@ -163,7 +163,7 @@ class FootnoteExtension(Extension): return self.unique_ref('fnref{}{}'.format(self.get_separator(), id), found) def makeFootnotesDiv(self, root): - """ Return div of footnotes as et Element. """ + """ Return `div` of footnotes as `etree` Element. """ if not list(self.footnotes.keys()): return None @@ -180,9 +180,9 @@ class FootnoteExtension(Extension): for index, id in enumerate(self.footnotes.keys(), start=1): li = etree.SubElement(ol, "li") li.set("id", self.makeFootnoteId(id)) - # Parse footnote with surrogate parent as li cannot be used. - # List block handlers have special logic to deal with li. - # When we are done parsing, we will copy everything over to li. + # Parse footnote with surrogate parent as `li` cannot be used. + # List block handlers have special logic to deal with `li`. + # When we are done parsing, we will copy everything over to `li`. self.parser.parseChunk(surrogate_parent, self.footnotes[id]) for el in list(surrogate_parent): li.append(el) @@ -296,7 +296,7 @@ class FootnoteBlockProcessor(BlockProcessor): class FootnoteInlineProcessor(InlineProcessor): - """ InlinePattern for footnote markers in a document's body text. """ + """ `InlinePattern` for footnote markers in a document's body text. """ def __init__(self, pattern, footnotes): super().__init__(pattern) @@ -325,7 +325,7 @@ class FootnotePostTreeprocessor(Treeprocessor): self.footnotes = footnotes def add_duplicates(self, li, duplicates): - """ Adjust current li and add the duplicates: fnref2, fnref3, etc. """ + """ Adjust current `li` and add the duplicates: `fnref2`, `fnref3`, etc. """ for link in li.iter('a'): # Find the link that needs to be duplicated. if link.attrib.get('class', '') == 'footnote-backref': @@ -407,5 +407,5 @@ class FootnotePostprocessor(Postprocessor): def makeExtension(**kwargs): # pragma: no cover - """ Return an instance of the FootnoteExtension """ + """ Return an instance of the `FootnoteExtension` """ return FootnoteExtension(**kwargs) diff --git a/markdown/extensions/legacy_attrs.py b/markdown/extensions/legacy_attrs.py index 445aba1..6e05e76 100644 --- a/markdown/extensions/legacy_attrs.py +++ b/markdown/extensions/legacy_attrs.py @@ -26,8 +26,8 @@ An extension to Python Markdown which implements legacy attributes. Prior to Python-Markdown version 3.0, the Markdown class had an `enable_attributes` keyword which was on by default and provided for attributes to be defined for elements using the format `{@key=value}`. This extension is provided as a replacement for -backward compatibility. New documents should be authored using attr_lists. However, -numerious documents exist which have been using the old attribute format for many +backward compatibility. New documents should be authored using `attr_lists`. However, +numerous documents exist which have been using the old attribute format for many years. This extension can be used to continue to render those documents correctly. """ diff --git a/markdown/extensions/legacy_em.py b/markdown/extensions/legacy_em.py index 360988b..bc147a6 100644 --- a/markdown/extensions/legacy_em.py +++ b/markdown/extensions/legacy_em.py @@ -45,5 +45,5 @@ class LegacyEmExtension(Extension): def makeExtension(**kwargs): # pragma: no cover - """ Return an instance of the LegacyEmExtension """ + """ Return an instance of the `LegacyEmExtension` """ return LegacyEmExtension(**kwargs) diff --git a/markdown/extensions/md_in_html.py b/markdown/extensions/md_in_html.py index ec7dcba..92afecf 100644 --- a/markdown/extensions/md_in_html.py +++ b/markdown/extensions/md_in_html.py @@ -25,7 +25,8 @@ import xml.etree.ElementTree as etree class HTMLExtractorExtra(HTMLExtractor): """ - Override HTMLExtractor and create etree Elements for any elements which should have content parsed as Markdown. + Override `HTMLExtractor` and create `etree` `Elements` for any elements which should have content parsed as + Markdown. """ def __init__(self, md, *args, **kwargs): @@ -56,17 +57,17 @@ class HTMLExtractorExtra(HTMLExtractor): super().close() # Handle any unclosed tags. if self.mdstack: - # Close the outermost parent. handle_endtag will close all unclosed children. + # Close the outermost parent. `handle_endtag` will close all unclosed children. self.handle_endtag(self.mdstack[0]) def get_element(self): - """ Return element from treebuilder and reset treebuilder for later use. """ + """ Return element from `treebuilder` and reset `treebuilder` for later use. """ element = self.treebuilder.close() self.treebuilder = etree.TreeBuilder() return element def get_state(self, tag, attrs): - """ Return state from tag and `markdown` attr. One of 'block', 'span', or 'off'. """ + """ Return state from tag and `markdown` attribute. One of 'block', 'span', or 'off'. """ md_attr = attrs.get('markdown', '0') if md_attr == 'markdown': # `<tag markdown>` is the same as `<tag markdown='1'>`. @@ -100,7 +101,7 @@ class HTMLExtractorExtra(HTMLExtractor): return if tag in self.block_level_tags and (self.at_line_start() or self.intail): - # Valueless attr (ex: `<tag checked>`) results in `[('checked', None)]`. + # Valueless attribute (ex: `<tag checked>`) results in `[('checked', None)]`. # Convert to `{'checked': 'checked'}`. attrs = {key: value if value is not None else key for key, value in attrs} state = self.get_state(tag, attrs) @@ -157,7 +158,7 @@ class HTMLExtractorExtra(HTMLExtractor): # Check if element has a tail if not blank_line_re.match( self.rawdata[self.line_offset + self.offset + len(self.get_endtag_text(tag)):]): - # More content exists after endtag. + # More content exists after `endtag`. self.intail = True else: # Treat orphan closing tag as a span level tag. @@ -209,8 +210,8 @@ class HTMLExtractorExtra(HTMLExtractor): def parse_pi(self, i): if self.at_line_start() or self.intail or self.mdstack: - # The same override exists in HTMLExtractor without the check - # for mdstack. Therefore, use HTMLExtractor's parent instead. + # The same override exists in `HTMLExtractor` without the check + # for `mdstack`. Therefore, use parent of `HTMLExtractor` instead. return super(HTMLExtractor, self).parse_pi(i) # This is not the beginning of a raw block so treat as plain data # and avoid consuming any tags which may follow (see #1066). @@ -219,8 +220,8 @@ class HTMLExtractorExtra(HTMLExtractor): def parse_html_declaration(self, i): if self.at_line_start() or self.intail or self.mdstack: - # The same override exists in HTMLExtractor without the check - # for mdstack. Therefore, use HTMLExtractor's parent instead. + # The same override exists in `HTMLExtractor` without the check + # for `mdstack`. Therefore, use parent of `HTMLExtractor` instead. return super(HTMLExtractor, self).parse_html_declaration(i) # This is not the beginning of a raw block so treat as plain data # and avoid consuming any tags which may follow (see #1066). @@ -240,19 +241,19 @@ class HtmlBlockPreprocessor(Preprocessor): class MarkdownInHtmlProcessor(BlockProcessor): - """Process Markdown Inside HTML Blocks which have been stored in the HtmlStash.""" + """Process Markdown Inside HTML Blocks which have been stored in the `HtmlStash`.""" def test(self, parent, block): - # ALways return True. `run` will return `False` it not a valid match. + # Always return True. `run` will return `False` it not a valid match. return True def parse_element_content(self, element): """ - Recursively parse the text content of an etree Element as Markdown. + Recursively parse the text content of an `etree` Element as Markdown. Any block level elements generated from the Markdown will be inserted as children of the element in place of the text content. All `markdown` attributes are removed. For any elements in which Markdown parsing has - been disabled, the text content of it and its chidlren are wrapped in an `AtomicString`. + been disabled, the text content of it and its children are wrapped in an `AtomicString`. """ md_attr = element.attrib.pop('markdown', 'off') @@ -301,7 +302,7 @@ class MarkdownInHtmlProcessor(BlockProcessor): element.insert(0, child) elif md_attr == 'span': - # Span level parsing will be handled by inlineprocessors. + # Span level parsing will be handled by inline processors. # Walk children here to remove any `markdown` attributes. for child in list(element): self.parse_element_content(child) @@ -329,7 +330,7 @@ class MarkdownInHtmlProcessor(BlockProcessor): # Cleanup stash. Replace element with empty string to avoid confusing postprocessor. self.parser.md.htmlStash.rawHtmlBlocks.pop(index) self.parser.md.htmlStash.rawHtmlBlocks.insert(index, '') - # Confirm the match to the blockparser. + # Confirm the match to the `blockparser`. return True # No match found. return False @@ -337,7 +338,7 @@ class MarkdownInHtmlProcessor(BlockProcessor): class MarkdownInHTMLPostprocessor(RawHtmlPostprocessor): def stash_to_string(self, text): - """ Override default to handle any etree elements still in the stash. """ + """ Override default to handle any `etree` elements still in the stash. """ if isinstance(text, etree.Element): return self.md.serializer(text) else: @@ -352,7 +353,7 @@ class MarkdownInHtmlExtension(Extension): # Replace raw HTML preprocessor md.preprocessors.register(HtmlBlockPreprocessor(md), 'html_block', 20) - # Add blockprocessor which handles the placeholders for etree elements + # Add `blockprocessor` which handles the placeholders for `etree` elements md.parser.blockprocessors.register( MarkdownInHtmlProcessor(md.parser), 'markdown_block', 105 ) diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py index 10dee11..8a93863 100644 --- a/markdown/extensions/meta.py +++ b/markdown/extensions/meta.py @@ -33,7 +33,7 @@ class MetaExtension (Extension): """ Meta-Data extension for Python-Markdown. """ def extendMarkdown(self, md): - """ Add MetaPreprocessor to Markdown instance. """ + """ Add `MetaPreprocessor` to Markdown instance. """ md.registerExtension(self) self.md = md md.preprocessors.register(MetaPreprocessor(md), 'meta', 27) diff --git a/markdown/extensions/nl2br.py b/markdown/extensions/nl2br.py index 6c7491b..23d5603 100644 --- a/markdown/extensions/nl2br.py +++ b/markdown/extensions/nl2br.py @@ -1,5 +1,5 @@ """ -NL2BR Extension +`NL2BR` Extension =============== A Python-Markdown extension to treat newlines as hard breaks; like @@ -8,7 +8,7 @@ GitHub-flavored Markdown does. See <https://Python-Markdown.github.io/extensions/nl2br> for documentation. -Oringinal code Copyright 2011 [Brian Neal](https://deathofagremmie.com/) +Original code Copyright 2011 [Brian Neal](https://deathofagremmie.com/) All changes Copyright 2011-2014 The Python Markdown Project diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index c4bfd58..15e5784 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -48,9 +48,9 @@ SmartyPants license: of this software, even if advised of the possibility of such damage. -smartypants.py license: +`smartypants.py` license: - smartypants.py is a derivative work of SmartyPants. + `smartypants.py` is a derivative work of SmartyPants. Copyright (c) 2004, 2007 Chad Miller <http://web.chad.org/> Redistribution and use in source and binary forms, with or without @@ -95,7 +95,7 @@ openingQuotesBase = ( r'(\s' # a whitespace char r'| ' # or a non-breaking space entity r'|--' # or dashes - r'|–|—' # or unicode + r'|–|—' # or Unicode r'|&[mn]dash;' # or named dash entities r'|–|—' # or decimal entities r')' @@ -242,7 +242,7 @@ class SmartyExtension(Extension): self.educateQuotes(md) if configs['smart_angled_quotes']: self.educateAngledQuotes(md) - # Override HTML_RE from inlinepatterns.py so that it does not + # Override `HTML_RE` from `inlinepatterns.py` so that it does not # process tags with duplicate closing quotes. md.inlinePatterns.register(HtmlInlineProcessor(HTML_STRICT_RE, md), 'html', 90) if configs['smart_dashes']: diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index c8b1024..a72103f 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -225,7 +225,7 @@ class TableExtension(Extension): super().__init__(**kwargs) def extendMarkdown(self, md): - """ Add an instance of TableProcessor to BlockParser. """ + """ Add an instance of `TableProcessor` to `BlockParser`. """ if '|' not in md.ESCAPED_CHARS: md.ESCAPED_CHARS.append('|') processor = TableProcessor(md.parser, self.getConfigs()) diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 1ded18d..9927b99 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -5,7 +5,7 @@ Table of Contents Extension for Python-Markdown See <https://Python-Markdown.github.io/extensions/toc> for documentation. -Oringinal code Copyright 2008 [Jack Miller](https://codezen.org/) +Original code Copyright 2008 [Jack Miller](https://codezen.org/) All changes Copyright 2008-2014 The Python Markdown Project @@ -26,7 +26,7 @@ import xml.etree.ElementTree as etree def slugify(value, separator, unicode=False): """ Slugify a string, to make it URL friendly. """ if not unicode: - # Replace Extended Latin characters with ASCII, i.e. žlutý → zluty + # Replace Extended Latin characters with ASCII, i.e. `žlutý` => `zluty` value = unicodedata.normalize('NFKD', value) value = value.encode('ascii', 'ignore').decode('ascii') value = re.sub(r'[^\w\s-]', '', value).strip().lower() @@ -179,7 +179,7 @@ class TocTreeprocessor(Treeprocessor): ''' Iterator wrapper to get allowed parent and child all at once. ''' # We do not allow the marker inside a header as that - # would causes an enless loop of placing a new TOC + # would causes an endless loop of placing a new TOC # inside previously generated TOC. for child in node: if not self.header_rgx.match(child.tag) and child.tag not in ['pre', 'code']: @@ -194,13 +194,13 @@ class TocTreeprocessor(Treeprocessor): continue # To keep the output from screwing up the - # validation by putting a <div> inside of a <p> - # we actually replace the <p> in its entirety. + # validation by putting a `<div>` inside of a `<p>` + # we actually replace the `<p>` in its entirety. - # The <p> element may contain more than a single text content - # (nl2br can introduce a <br>). In this situation, c.text returns + # The `<p>` element may contain more than a single text content + # (`nl2br` can introduce a `<br>`). In this situation, `c.text` returns # the very first content, ignore children contents or tail content. - # len(c) == 0 is here to ensure there is only text in the <p>. + # `len(c) == 0` is here to ensure there is only text in the `<p>`. if c.text and c.text.strip() == self.marker and len(c) == 0: for i in range(len(p)): if p[i] == c: @@ -214,7 +214,7 @@ class TocTreeprocessor(Treeprocessor): level = 6 elem.tag = 'h%d' % level - def add_anchor(self, c, elem_id): # @ReservedAssignment + def add_anchor(self, c, elem_id): anchor = etree.Element("a") anchor.text = c.text anchor.attrib["href"] = "#" + elem_id @@ -368,11 +368,6 @@ class TocExtension(Extension): self.md = md self.reset() tocext = self.TreeProcessorClass(md, self.getConfigs()) - # Headerid ext is set to '>prettify'. With this set to '_end', - # it should always come after headerid ext (and honor ids assigned - # by the header id extension) if both are used. Same goes for - # attr_list extension. This must come last because we don't want - # to redefine ids after toc is created. But we do want toc prettified. md.treeprocessors.register(tocext, 'toc', 5) def reset(self): diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py index cddee7a..d32d912 100644 --- a/markdown/extensions/wikilinks.py +++ b/markdown/extensions/wikilinks.py @@ -22,7 +22,7 @@ import re def build_url(label, base, end): - """ Build a url from the label, a base, and an end. """ + """ Build a URL from the label, a base, and an end. """ clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label) return '{}{}{}'.format(base, clean_label, end) @@ -69,7 +69,7 @@ class WikiLinksInlineProcessor(InlineProcessor): return a, m.start(0), m.end(0) def _getMeta(self): - """ Return meta data or config data. """ + """ Return meta data or `config` data. """ base_url = self.config['base_url'] end_url = self.config['end_url'] html_class = self.config['html_class'] |
