Skip to content

Addition: Syntax highlighting in markdown #3770

@bjornasm

Description

@bjornasm

I initially researched the possibilities to get a live markdown preview in Micro. However, after thinking about the problem I realized that the syntax highlighting in a markdown file is (for me at least) a good enough preview. But what I really missed was syntax highlighting of fenced code blocks. This might be a solved problem, but I didn't find any other solution.

I realized that using the syntax yaml files I could pretty easily define any fenced code block and inside that rule set include all the syntax highlighting rules for Python.

#(markdown.yaml syntax file)
# ----- Rule set for language: python -----
- comment:
    start: (?i)^```python$
    end: ^```$
    rules:

I then extended this to a project that creates a .yaml file. That gives syntax highlighting for any (or all) language that is in the Micro repository, as long its inside a fenced code block:

```python
def greet():
    for i in range(10):
        print(f"Hello World, {i}!")
```

```javascript
function greet() {
    for (let i = 0; i < 10; i++) {
        console.log(`Hello World, ${i}!`);
    }
}
```

```java
public class Main {
    public static void greet() {
        for (int i = 0; i < 10; i++) {
            System.out.println("Hello World, " + i + "!");
        }
    }
}

Hope this is something more people will find usefull. If the maintainers are interested in including the resulting .yaml file or any of the code I'll be glad to issue a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions