facelessuser / MarkdownPreview

Markdown preview and build plugin for Sublime Text https://facelessuser.github.io/MarkdownPreview/
Other
402 stars 53 forks source link

The `attr_list` Is Not Applied #171

Closed RoyiAvital closed 9 months ago

RoyiAvital commented 9 months ago

I have a MarkDown document configured as:

---
# Meta Data
title: My Title
summary: Some summary.
description: Some description.

# Settings
settings:
    allow_css_overrides: true
    image_path_conversion: base64
    strip_yaml_front_matter: true

    js:
        - https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js
        - res://MarkdownPreview/js/math_config.js
        - https://unpkg.com/mermaid@10.3.0/dist/mermaid.min.js
        # - res://MarkdownPreview/js/mermaid_config.js
        # - res://MarkdownPreview/js/mermaid.js

    markdown_extensions:
        - markdown.extensions.abbr
        - markdown.extensions.admonition
        - markdown.extensions.attr_list
        - markdown.extensions.def_list
        - markdown.extensions.footnotes
        - markdown.extensions.md_in_html
        - markdown.extensions.meta
        - markdown.extensions.sane_lists
        - markdown.extensions.smarty
        - markdown.extensions.tables
        - markdown.extensions.toc:
            title: Table of Contents
            toc_depth: 2-3
        - markdown.extensions.wikilinks
        - markdown_captions.markdown_captions
        - pymdownx.arithmatex:
            generic: true
            smart_dollar: false
        - pymdownx.betterem
        - pymdownx.emoji:
            options:
                attributes:
                    align: absmiddle
                    height: 20px
                    width: 20px
        - pymdownx.magiclink:
            repo_url_shortener: true
            repo_url_shorthand: true
        - pymdownx.mark
        - pymdownx.superfences:
            custom_fences:
                - name: mermaid
                  class: mermaid
                  # format: !!python/name:pymdownx.superfences.fence_code_format
                  format: !!python/name:pymdownx.superfences.fence_div_format
        - pymdownx.tasklist
        - pymdownx.tilde:
            subscript: false
---

my text {: class="foo bar"}.

The output doesn't apply the class to the text. More than, that, is just appears as my text {: class="foo bar"}..

I am following the documentation in https://python-markdown.github.io/extensions/attr_list/.

RoyiAvital commented 9 months ago

OK, It seems attr_list won't work in this case.

I wonder if there is an alternative which works similar to how attribution are applied in Quarto.

So for inline it can work like: [my text]{: .somecalss #someID}.

facelessuser commented 9 months ago

Yeah, unfortunately, attr_list doesn't work this way. There may be some Python Markdown extension out there that does something like you want, but you would need to hunt it down.

In short, attr_list need to be applied to an element, and in your case there isn't one to apply it to. There are some rules in how it gets applied, but sometimes it just doesn't play nice with certain extensions.

You can apply it to the entire block:

my text.
{: .somecalss #someID}

But I imagine that is not what you want.

You can apply it to situations where the text is already wrapped in an element:

**my text**{: .somecalss #someID}.

Unfortunately, it doesn't play nice with raw HTML:

<span>my text</span>{: class="foo bar"}.

Of course, plain HTML will always work.

<span class="foo bar">my text</span>