Skip to content

Apply newline replacement in renderPattern to support multi-line image code blocks in reStructuredText (RST) files.#27

Open
pblommendaal wants to merge 1 commit intodzylikecode:masterfrom
pblommendaal:feature/newline-replacement
Open

Apply newline replacement in renderPattern to support multi-line image code blocks in reStructuredText (RST) files.#27
pblommendaal wants to merge 1 commit intodzylikecode:masterfrom
pblommendaal:feature/newline-replacement

Conversation

@pblommendaal
Copy link

Applies newline replacement in renderPattern to support multi-line image code blocks in reStructuredText (RST) files

In RST files, image code blocks often need to span multiple lines, which was previously unsupported. This change may also benefit other formats that require multi-line syntax in the render pattern.

For example, you can now use a render map with \n like:

**/*.rst => .. image:: ${imagePath}\n :class: browser-screenshot with-shadow\n :alt: ${imagePath}

Reference: RST image directive documentation

…e code blocks in reStructuredText (RST) files.
@dzylikecode
Copy link
Owner

dzylikecode commented Oct 30, 2024

A newline works if you apply the setting to the settings.json file. The problem is that if you set it through the UI, vscode will escape the line breaks, as seen in the example.

{
  "mdPasteEnhanced.renderMap": [
    "**/*.md  => ![${userVar}](${imagePath})",
    "**/*.typ => #image(\"${imagePath}\"${userVar})",
    "**/*.rst => .. image::  ${imagePath}\n    :class: browser-screenshot with-shadow\n    :alt: ${imagePath}", // set directly in json
    "**/*.rst => .. image::  ${imagePath}\\n    :class: browser-screenshot with-shadow\\n    :alt: ${imagePath}", // set via UI
    "**/*     => ${imagePath}",
  ]
}

image

@pblommendaal
Copy link
Author

Thanks for confirming that newlines work in settings.json. However, for users who prefer using the UI, escaped line breaks aren't visible, leading to confusion if the setting is later reviewed in the UI. By implementing this update, we provide a seamless experience for reStructuredText users, ensuring both JSON and UI configurations display consistently without unexpected escapes.

My second pull request supports the hover menu for .rst files and directly relates to this change. Additionally, note that when editing the settings.json directly it still prevents the hover menu from working for rst files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants