Skip to content

Commit

Permalink
Support pulldown-cmark v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans committed Feb 5, 2024
1 parent ddd7b79 commit 8ffb758
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 117 deletions.
30 changes: 15 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ addopts = ["--strict-config", "--strict-markers"]
xfail_strict = true

[tool.ruff]
line-length = 80
preview = true
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true
line-ending = "lf"
skip-magic-trailing-comma = true

[tool.ruff.lint]
ignore = [
"ANN101",
"ANN102",
Expand Down Expand Up @@ -123,31 +133,21 @@ ignore = [
"TRY400",
]
ignore-init-module-imports = true
line-length = 80
preview = true
select = ["ALL"]
target-version = "py37"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["FBT001", "S101"]

[tool.ruff.flake8-self]
[tool.ruff.lint.flake8-self]
ignore-names = ["_name_", "_value_"]

[tool.ruff.flake8-unused-arguments]
ignore-variadic-names = true

[tool.ruff.format]
line-ending = "lf"
skip-magic-trailing-comma = true

[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true
required-imports = ["from __future__ import annotations"]
split-on-trailing-comma = false

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.pyupgrade]
[tool.ruff.lint.pyupgrade]
keep-runtime-typing = true
22 changes: 9 additions & 13 deletions python/pyromark/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ def parse_args(args: Optional[Sequence[str]]) -> argparse.Namespace:
parser.add_argument(
"-v", "--version", action="version", version=pyromark.__version__
)
for extension in pyromark.Extensions:
name = extension._name_.lower().replace( # type: ignore[union-attr]
"_", "-"
for ext_name in pyromark.Extensions.__members__:
parser.add_argument(
"--" + ext_name.lower().replace("_", "-"), action="store_true"
)
parser.add_argument(f"--{name}", action="store_true")
parser.add_argument(
"file",
type=argparse.FileType(),
Expand All @@ -33,16 +32,13 @@ def main(args: Optional[Sequence[str]] = None) -> None:
with parsed_args.file as f:
content = f.read()

extensions = pyromark.Extensions(0)
for extension in pyromark.Extensions:
extension_enabled = getattr(
parsed_args,
extension._name_.lower(), # type: ignore[union-attr]
)
if extension_enabled:
extensions |= extension
exts = pyromark.Extensions(0)
for ext_name, ext in pyromark.Extensions.__members__.items():
ext_enabled = getattr(parsed_args, ext_name.lower())
if ext_enabled:
exts |= ext

html = pyromark.markdown(content, extensions=extensions)
html = pyromark.markdown(content, extensions=exts)
print(html, end="")


Expand Down
10 changes: 8 additions & 2 deletions python/pyromark/_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class Extensions(IntFlag):
| pyromark.Extensions.ENABLE_TASKLISTS
| pyromark.Extensions.ENABLE_SMART_PUNCTUATION
| pyromark.Extensions.ENABLE_HEADING_ATTRIBUTES
| pyromark.Extensions.ENABLE_YAML_STYLE_METADATA_BLOCKS
| pyromark.Extensions.ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS
| pyromark.Extensions.ENABLE_OLD_FOOTNOTES
)
```
"""

ENABLE_TABLES = 1 << 1
"""<https://github.github.com/gfm/#tables-extension->"""
ENABLE_FOOTNOTES = 1 << 2
"""<https://www.markdownguide.org/extended-syntax/#footnotes>"""
"""<https://docs.rs/pulldown-cmark/0.10.0/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_FOOTNOTES>"""
ENABLE_STRIKETHROUGH = 1 << 3
"""<https://github.github.com/gfm/#strikethrough-extension->"""
ENABLE_TASKLISTS = 1 << 4
Expand All @@ -41,7 +44,10 @@ class Extensions(IntFlag):
| --- | — |
"""
ENABLE_HEADING_ATTRIBUTES = 1 << 6
"""<https://docs.rs/pulldown-cmark/latest/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_HEADING_ATTRIBUTES>"""
"""<https://docs.rs/pulldown-cmark/0.10.0/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_HEADING_ATTRIBUTES>"""
ENABLE_YAML_STYLE_METADATA_BLOCKS = 1 << 7
"""<https://docs.rs/pulldown-cmark/0.10.0/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_YAML_STYLE_METADATA_BLOCKS>"""
ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS = 1 << 8
"""<https://docs.rs/pulldown-cmark/0.10.0/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS>"""
ENABLE_OLD_FOOTNOTES = (1 << 9) | (1 << 2)
"""<https://docs.rs/pulldown-cmark/0.10.0/pulldown_cmark/struct.Options.html#associatedconstant.ENABLE_OLD_FOOTNOTES>"""
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use pyo3::prelude::*;
/// | pyromark.Extensions.ENABLE_TASKLISTS
/// | pyromark.Extensions.ENABLE_SMART_PUNCTUATION
/// | pyromark.Extensions.ENABLE_HEADING_ATTRIBUTES
/// | pyromark.Extensions.ENABLE_YAML_STYLE_METADATA_BLOCKS
/// | pyromark.Extensions.ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS
/// | pyromark.Extensions.ENABLE_OLD_FOOTNOTES
/// )
/// )
/// ```
Expand Down Expand Up @@ -52,6 +55,9 @@ impl Markdown {
/// | pyromark.Extensions.ENABLE_TASKLISTS
/// | pyromark.Extensions.ENABLE_SMART_PUNCTUATION
/// | pyromark.Extensions.ENABLE_HEADING_ATTRIBUTES
/// | pyromark.Extensions.ENABLE_YAML_STYLE_METADATA_BLOCKS
/// | pyromark.Extensions.ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS
/// | pyromark.Extensions.ENABLE_OLD_FOOTNOTES
/// )
/// )
/// print(html) # <h1>Hello world</h1>\n
Expand Down
Loading

0 comments on commit 8ffb758

Please sign in to comment.