Giter Site home page Giter Site logo

sivakov512 / python-markdown-full-yaml-metadata Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 4.0 57 KB

YAML metadata extension for Python-Markdown

License: MIT License

Python 97.06% Makefile 2.94%
markdown markdown-extension markdown-metadata metadata python python3 yaml

python-markdown-full-yaml-metadata's People

Contributors

holzhaus avatar philbarker avatar renovate[bot] avatar sivakov512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-markdown-full-yaml-metadata's Issues

Allow specifing custom loader using configuration option

Currently there is no way to use the yaml.BaseLoader for example. The full loader is unsafe for arbitrary user data and also converts strings like 2020-01-01 10:00:00 to datetime.datetime objects, which might be undesired.

Add option to attempt splitting metadata using `\n\n` if metadata delimiters are missing

This might work for very simple metadata, like:

title: Foo bar
date: 2020-01-01 10:00:00

This is text

If the metadata delimiters are not found and the option is enabled, the plugin could do something like this:

meta, sep, content = text.partition("\n\n")
try:
    metadata = yaml.load(meta, Loader=...)
except yaml.error.YAMLError:
    content = text
    metadata = {}
else:
    # Prevent false-positives if the text does not begin with a metadata block
    if isinstance(metadata, str):
        metadata = {}
        content = text

self.md.Meta = metadata
return content

RFE: don't pin dependencies exactly

This extension pins every dependency exactly. That's a fine strategy for an end-user application, but for a library it's not really the right thing to do, as you inevitably end up with conflicting dependencies in a project that consumes the library. Please would you consider having more liberal dependencies (eg. markdown>3.0, rather than markdown==3.0.1) for example.

Thanks for a great extension, by the way!

Move setup_requires to pyproject.yaml

When build system (setuptools) requirements are specified in setup.py, they end up being installed by distutils, even when pip installing. Because distutils is bit-rotting, it doesn't work with system installed openssl.

Locally, for me, that means distutils doesn't know about some SSL CA certs, and as such, a pip install markdown-full-yaml-metadata will fail when trying to install setuptools_markdown due to being unable to validate the SSL cert (I am behind a coorporate proxy which MITMs all traffic and resigns with a local cert).

Moving the setup_requires deps to pyproject.toml fixes this - I suggest something like this:

[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools>=36.6", "setuptools_markdown", "wheel",]
build-backend = "setuptools.build_meta"

md = markdown.Markdown(['full_yaml_metadata']) didn't work for me

Basic usage on pypi invokes extension with
md = markdown.Markdown(['full_yaml_metadata'])

I got the error:

>>> md = markdown.Markdown(['full_yaml_metadata'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes 1 positional argument but 2 were given

But this did work (or at least gave another error)
md = markdown.Markdown(extensions=['full_yaml_metadata'])

KeyError: 'configs' on running

After getting extension to load properly, got error:

>>> import markdown
>>> md = markdown.Markdown(extensions=['full_yaml_metadata'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/core.py", line 100, in __init__
    configs=kwargs.get('extension_configs', {}))
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/core.py", line 126, in registerExtensions
    ext = self.build_extension(ext, configs.get(ext, {}))
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/core.py", line 181, in build_extension
    return module.makeExtension(**configs)
  File "/home/phil/Share/Projects/full-yaml-test/python-markdown-full-yaml-metadata/full_yaml_metadata.py", line 45, in makeExtension
    return FullYamlMetadataExtension(configs=configs)
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/extensions/__init__.py", line 42, in __init__
    self.setConfigs(kwargs)
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/extensions/__init__.py", line 73, in setConfigs
    self.setConfig(key, value)
  File "/home/phil/Share/Projects/full-yaml-test/venv/lib/python3.6/site-packages/markdown/extensions/__init__.py", line 61, in setConfig
    if isinstance(self.config[key][0], bool):
KeyError: 'configs'

I fixed by changing

def makeExtension(configs: dict={}):
    return FullYamlMetadataExtension(configs=configs)

to

def makeExtension(*args, **kwargs):
    return FullYamlMetadataExtension(*args, **kwargs)

Hope this helps.

Spell is incorrect in pypi

I guess there could be a mistake in pypi name. It is makrdown-xxx in pypi rather than the correct one markdown...

Using pre-commit hooks

I noticed that some parts of the code don't pass your linter checks. This is common for projects with only one main developer where you sometimes push directly instead of opening a PR. I suggest to use pre-commit, which checks that all linters pass before committing. It also takes care dev dependency installation in a venv (so you can remove dev dependencies from requirements.txt.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/publish.yml
  • actions/checkout v4
  • actions/setup-python v5
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/cache v4
  • actions/cache v4
  • actions/checkout v4
  • actions/setup-python v5
  • actions/cache v4
  • actions/cache v4
pep621
pyproject.toml
poetry
pyproject.toml
  • python ^3.8.1
  • markdown ^3.4.1
  • pyyaml ^6.0
  • black ^24.0.0
  • flake8 ^7.0.0
  • flake8-debugger ^4.1.2
  • flake8-isort ^6.0.0
  • flake8-print ^5.0.0
  • flake8-quotes ^3.3.2
  • isort ^5.11.4
  • mypy ^1.0.0
  • pytest ^8.0.0
  • pytest-cov ^4.0.0
  • coveralls ^3.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.