euporie.core.convert.formats.html

Contain functions which convert data to html format.

Functions

amsmath_plugin(md, *[, renderer])

Parses TeX math equations, without any surrounding delimiters, only for top-level amsmath environments:

detect_lexer([text, path, language])

Detect the pygments lexer for a file.

dollarmath_plugin(md, *[, allow_labels, ...])

Plugin for parsing dollar enclosed math, e.g.

get_app()

Get the current active (running) Application.

highlight(code, lexer, formatter[, outfile])

This is the most high-level highlighting function.

markdown_to_html_markdown_it(datum[, cols, ...])

Convert markdown to HTML using markdownit_py.

register(from_, to[, filter_, weight])

Add a converter to the centralized format conversion system.

texmath_plugin(md[, delimiters, macros])

Plugin ported from markdown-it-texmath.

Classes

HtmlFormatter(**options)

Format tokens as HTML 4 <span> tags.

MarkdownIt(config, options_update, ...)

MarkdownParser(config, options_update, ...)

Subclas the markdown parser to allow file: URIs.

class euporie.core.convert.formats.html.MarkdownParser(config: str | markdown_it.utils.PresetType = 'commonmark', options_update: collections.abc.Mapping[str, Any] | None = None, *, renderer_cls: ~collections.abc.Callable[[~markdown_it.main.MarkdownIt], ~markdown_it.renderer.RendererProtocol] = <class 'markdown_it.renderer.RendererHTML'>)

Bases: MarkdownIt

Subclas the markdown parser to allow file: URIs.

add_render_rule(name: str, function: Callable[[...], Any], fmt: str = 'html') None

Add a rule for rendering a particular Token type.

Only applied when renderer.__output__ == fmt

configure(presets: str | markdown_it.utils.PresetType, options_update: collections.abc.Mapping[str, Any] | None = None) MarkdownIt

Batch load of all options and component settings. This is an internal method, and you probably will not need it. But if you will - see available presets and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)

We strongly recommend to use presets instead of direct config loads. That will give better compatibility with next versions.

disable(names: str | collections.abc.Iterable[str], ignoreInvalid: bool = False) MarkdownIt

The same as [[MarkdownIt.enable]], but turn specified rules off. (chainable)

Parameters:
  • names – rule name or list of rule names to disable.

  • ignoreInvalid – set true to ignore errors when rule not found.

enable(names: str | collections.abc.Iterable[str], ignoreInvalid: bool = False) MarkdownIt

Enable list or rules. (chainable)

Parameters:
  • names – rule name or list of rule names to enable.

  • ignoreInvalid – set true to ignore errors when rule not found.

It will automatically find appropriate components, containing rules with given names. If rule not found, and ignoreInvalid not set - throws exception.

Example:

md = MarkdownIt().enable(['sub', 'sup']).disable('smartquotes')
get_active_rules() dict[str, list[str]]

Return the names of all active rules.

get_all_rules() dict[str, list[str]]

Return the names of all active rules.

Normalize destination URLs in links

[label]:   destination   'title'
        ^^^^^^^^^^^
normalizeLinkText(link: str) str

Normalize autolink content

<destination>
~~~~~~~~~~~
parse(src: str, env: Optional[MutableMapping[str, Any]] = None) list[markdown_it.token.Token]

Parse the source string to a token stream

Parameters:
  • src – source string

  • env – environment sandbox

Parse input string and return list of block tokens (special token type “inline” will contain list of inline tokens).

env is used to pass data between “distributed” rules and return additional metadata like reference info, needed for the renderer. It also can be used to inject data in specific cases. Usually, you will be ok to pass {}, and then pass updated object to renderer.

parseInline(src: str, env: Optional[MutableMapping[str, Any]] = None) list[markdown_it.token.Token]

The same as [[MarkdownIt.parse]] but skip all block rules.

Parameters:
  • src – source string

  • env – environment sandbox

It returns the block tokens list with the single inline element, containing parsed inline tokens in children property. Also updates env object.

render(src: str, env: Optional[MutableMapping[str, Any]] = None) Any

Render markdown string into html. It does all magic for you :).

Parameters:
  • src – source string

  • env – environment sandbox

Returns:

The output of the loaded renderer

env can be used to inject additional metadata ({} by default). But you will not need it with high probability. See also comment in [[MarkdownIt.parse]].

renderInline(src: str, env: Optional[MutableMapping[str, Any]] = None) Any

Similar to [[MarkdownIt.render]] but for single paragraph content.

Parameters:
  • src – source string

  • env – environment sandbox

Similar to [[MarkdownIt.render]] but for single paragraph content. Result will NOT be wrapped into <p> tags.

reset_rules() Generator[None, None, None]

A context manager, that will reset the current enabled rules on exit.

set(options: OptionsType) None

Set parser options (in the same format as in constructor). Probably, you will never need it, but you can change options after constructor call.

__Note:__ To achieve the best possible performance, don’t modify a markdown-it instance options on the fly. If you need multiple configurations it’s best to create multiple instances and initialize each with separate config.

use(plugin: Callable[[...], None], *params: Any, **options: Any) MarkdownIt

Load specified plugin with given params into current parser instance. (chainable)

It’s just a sugar to call plugin(md, params) with curring.

Example:

def func(tokens, idx):
    tokens[idx].content = tokens[idx].content.replace('foo', 'bar')
md = MarkdownIt().use(plugin, 'foo_replace', 'text', func)

Allow all link URIs.

async euporie.core.convert.formats.html.markdown_to_html_markdown_it(datum: Datum, cols: int | None = None, rows: int | None = None, fg: str | None = None, bg: str | None = None, extend: bool = True) str

Convert markdown to HTML using markdownit_py.