diff --git a/.gitignore b/.gitignore index f27916d..7b28751 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ ghostdriver.log # nox .nox/* + +venv* +.idea/* \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/m2r2.iml b/.idea/m2r2.iml new file mode 100644 index 0000000..8b8c395 --- /dev/null +++ b/.idea/m2r2.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..acbf29c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..a0adcf0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + { + "associatedIndex": 6 +} + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "v2", + "last_opened_file_path": "/home/daquintero/flexcompute/m2r2", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + 1703681877093 + + + + + + \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e55a3f..60c301e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,28 +12,43 @@ repos: language: system types: [python] args: [--max-line-length=88] - exclude: (docs|tests)/* + exclude: | + (?x)^( + docs*| + test* + )$ - id: isort name: isort entry: isort language: system types: [python] args: [--multi-line=3,--trailing-comma,--force-grid-wrap=0,--use-parentheses,--line-width=88] - exclude: (docs|tests)/* + exclude: | + (?x)^( + docs*| + test* + )$ - id: black name: black entry: black language: system types: [python] args: [] - language_version: python3.7 - exclude: (docs|tests)/* + exclude: | + (?x)^( + docs*| + test* + )$ - id: mypy name: mypy entry: mypy language: system types: [python] - exclude: (tests|docs)/* + exclude: | + (?x)^( + docs*| + test* + )$ - id: pylint name: pylint entry: pylint diff --git a/m2r2.py b/m2r2.py deleted file mode 100644 index e78d969..0000000 --- a/m2r2.py +++ /dev/null @@ -1,732 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -from __future__ import print_function, unicode_literals - -import os -import os.path -import re -import sys -from argparse import ArgumentParser, Namespace - -import mistune -from docutils import io, nodes, statemachine, utils -from docutils.parsers import rst -from docutils.utils import column_width -from pkg_resources import get_distribution - -__version__ = get_distribution("m2r2").version - -if sys.version_info < (3,): - from codecs import open as _open - - from urlparse import urlparse -else: - _open = open - from urllib.parse import urlparse - - -_is_sphinx = False -prolog = """\ -.. role:: raw-html-m2r(raw) - :format: html - -""" - -# for command-line use -parser = ArgumentParser() -options = Namespace() -parser.add_argument("input_file", nargs="*", help="files to convert to reST format") -parser.add_argument( - "--overwrite", - action="store_true", - default=False, - help="overwrite output file without confirmaion", -) -parser.add_argument( - "--dry-run", - action="store_true", - default=False, - help="print conversion result and not save output file", -) -parser.add_argument( - "--no-underscore-emphasis", - action="store_true", - default=False, - help="do not use underscore (_) for emphasis", -) -parser.add_argument( - "--parse-relative-links", - action="store_true", - default=False, - help="parse relative links into ref or doc directives", -) -parser.add_argument( - "--anonymous-references", - action="store_true", - default=False, - help="use anonymous references in generated rst", -) -parser.add_argument( - "--disable-inline-math", - action="store_true", - default=False, - help="disable parsing inline math", -) - - -def parse_options(): - parser.parse_known_args(namespace=options) - - -class RestBlockGrammar(mistune.BlockGrammar): - directive = re.compile( - r"^( *\.\..*?)\n(?=\S)", - re.DOTALL | re.MULTILINE, - ) - oneline_directive = re.compile( - r"^( *\.\..*?)$", - re.DOTALL | re.MULTILINE, - ) - rest_code_block = re.compile( - r"^::\s*$", - re.DOTALL | re.MULTILINE, - ) - - -class RestBlockLexer(mistune.BlockLexer): - grammar_class = RestBlockGrammar - default_rules = [ - "directive", - "oneline_directive", - "rest_code_block", - ] + mistune.BlockLexer.default_rules - - def parse_directive(self, m): - self.tokens.append({"type": "directive", "text": m.group(1)}) - - def parse_oneline_directive(self, m): - # reuse directive output - self.tokens.append({"type": "directive", "text": m.group(1)}) - - def parse_rest_code_block(self, m): - self.tokens.append({"type": "rest_code_block"}) - - -class RestInlineGrammar(mistune.InlineGrammar): - image_link = re.compile( - r"\[!\[(?P.*?)\]\((?P.*?)\).*?\]\((?P.*?)\)" - ) - rest_role = re.compile(r":.*?:`.*?`|`[^`]+`:.*?:") - rest_link = re.compile(r"`[^`]*?`_") - inline_math = re.compile(r"`\$(.*?)\$`") - eol_literal_marker = re.compile(r"(\s+)?::\s*$") - # add colon and space as special text - text = re.compile(r"^[\s\S]+?(?=[\\[\s\S]+?)\1{2}(?!\1)") - # _word_ or *word* - emphasis = re.compile( - r"^\b_((?:__|[^_])+?)_\b" # _word_ - r"|" - r"^\*(?P(?:\*\*|[^\*])+?)\*(?!\*)" # *word* - ) - - def no_underscore_emphasis(self): - self.double_emphasis = re.compile( - r"^\*{2}(?P[\s\S]+?)\*{2}(?!\*)" # **word** - ) - self.emphasis = re.compile(r"^\*(?P(?:\*\*|[^\*])+?)\*(?!\*)") # *word* - - -class RestInlineLexer(mistune.InlineLexer): - grammar_class = RestInlineGrammar - default_rules = [ - "image_link", - "rest_role", - "rest_link", - "eol_literal_marker", - ] + mistune.InlineLexer.default_rules - - def __init__(self, *args, **kwargs): - no_underscore_emphasis = kwargs.pop("no_underscore_emphasis", False) - disable_inline_math = kwargs.pop("disable_inline_math", False) - super(RestInlineLexer, self).__init__(*args, **kwargs) - if not _is_sphinx: - parse_options() - if no_underscore_emphasis or getattr(options, "no_underscore_emphasis", False): - self.rules.no_underscore_emphasis() - inline_maths = "inline_math" in self.default_rules - if disable_inline_math or getattr(options, "disable_inline_math", False): - if inline_maths: - self.default_rules.remove("inline_math") - elif not inline_maths: - self.default_rules.insert(0, "inline_math") - - def output_double_emphasis(self, m): - # may include code span - text = self.output(m.group("text")) - return self.renderer.double_emphasis(text) - - def output_emphasis(self, m): - # may include code span - text = self.output(m.group("text") or m.group(1)) - return self.renderer.emphasis(text) - - def output_image_link(self, m): - """Pass through rest role.""" - return self.renderer.image_link( - m.group("url"), m.group("target"), m.group("alt") - ) - - def output_rest_role(self, m): - """Pass through rest role.""" - return self.renderer.rest_role(m.group(0)) - - def output_rest_link(self, m): - """Pass through rest link.""" - return self.renderer.rest_link(m.group(0)) - - def output_inline_math(self, m): - """Pass through rest link.""" - return self.renderer.inline_math(m.group(1)) - - def output_eol_literal_marker(self, m): - """Pass through rest link.""" - marker = ":" if m.group(1) is None else "" - return self.renderer.eol_literal_marker(marker) - - -class RestRenderer(mistune.Renderer): - _include_raw_html = False - list_indent_re = re.compile(r"^(\s*(#\.|\*)\s)") - indent = " " * 3 - list_marker = "{#__rest_list_mark__#}" - hmarks = { - 1: "=", - 2: "-", - 3: "^", - 4: "~", - 5: '"', - 6: "#", - } - - def __init__(self, *args, **kwargs): - self.parse_relative_links = kwargs.pop("parse_relative_links", False) - self.anonymous_references = kwargs.pop("anonymous_references", False) - self.use_mermaid = kwargs.pop("use_mermaid", False) - super(RestRenderer, self).__init__(*args, **kwargs) - if not _is_sphinx: - parse_options() - if getattr(options, "parse_relative_links", False): - self.parse_relative_links = options.parse_relative_links - if getattr(options, "anonymous_references", False): - self.anonymous_references = options.anonymous_references - - def _indent_block(self, block): - return "\n".join( - self.indent + line if line else "" for line in block.splitlines() - ) - - def _raw_html(self, html): - self._include_raw_html = True - return r"\ :raw-html-m2r:`{}`\ ".format(html) - - def block_code(self, code, lang=None): - if lang == "math": - first_line = "\n.. math::\n\n" - elif lang == "mermaid" and self.use_mermaid: - first_line = "\n.. mermaid::\n\n" - elif lang: - first_line = "\n.. code-block:: {}\n\n".format(lang) - elif _is_sphinx: - first_line = "\n::\n\n" - else: - first_line = "\n.. code-block::\n\n" - return first_line + self._indent_block(code) + "\n" - - def block_quote(self, text): - # text includes some empty line - return "\n..\n\n{}\n\n".format(self._indent_block(text.strip("\n"))) - - def block_html(self, html): - """Rendering block level pure html content. - - :param html: text content of the html snippet. - """ - return "\n\n.. raw:: html\n\n" + self._indent_block(html) + "\n\n" - - def header(self, text, level, raw=None): - """Rendering header/heading tags like ``

`` ``

``. - - :param text: rendered text content for the header. - :param level: a number for the header level, for example: 1. - :param raw: raw text content of the header. - """ - return "\n{0}\n{1}\n".format(text, self.hmarks[level] * column_width(text)) - - def hrule(self): - """Rendering method for ``
`` tag.""" - return "\n----\n" - - def list(self, body, ordered=True): - """Rendering list tags like ``