Skip to content

Providing a default language for fenced code blocks #66

Closed
@mattrossman

Description

@mattrossman

Use case

In many markdown editors, I can write a fenced code blog and receive plaintext code styling without specifying a language.

E.g. writing this in GitHub markdown:

```
This is some plain text
```

Looks like this:

This is some plain text

Currently, when no language is specified on a fenced code block, this plugin outputs plain <pre> and <code> tags without a "language-*" class applied. In many Prism themes, such as the prism-okaidia theme shown in the plugin docs, this means the code block will not receive any styling. This is unexpected behavior for me.

Proposed Solution

To avoid breaking changes, I propose adding a defaultLanguage plugin option, which users may want to set to "plain". That way a generic code block like this:

```
This is some plain text
```

could be rendered as

<pre class="language-plain"><code class="language-plain">
This is some plain text
</code></pre>

Additional Context

Initially I thought I could set default languages like so:

eleventyConfig.addPlugin(pluginSyntaxHighlight, {
    preAttributes: {
      class: "language-plain",
    },
    codeAttributes: {
      class: "language-plain",
    },
});

However, as brought up in #52 this does not work. Resolving that issue could also resolve this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    open-questionFurther information is requested from the original poster.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions