sivakov512 / python-markdown-full-yaml-metadata Goto Github PK
View Code? Open in Web Editor NEWYAML metadata extension for Python-Markdown
License: MIT License
YAML metadata extension for Python-Markdown
License: MIT License
Website link in project description for pypi is wrong https://pypi.python.org/pypi/makrdown… ('makr', should be 'mark') -- I guess this worked before fixing #4
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.
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
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!
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"
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'])
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.
I guess there could be a mistake in pypi name. It is makrdown-xxx in pypi rather than the correct one markdown...
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
.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.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
pyproject.toml
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.