Skip to content

Conversation

@noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Jan 8, 2025

Hi 👋🏼

I gave a try at #234 and here comes my first PR.

It should fix multiple cases:

  • tilde-based fences
  • more than 3 characters (with consistent closing)
  • spaces between the fence and the language
  • language with extra parameters
  • support for Myst code, code-block and code-cell directives (no syntax highlighting, it requires a custom injection I might provide in another PR)
  • display directive name for unknown directive (and any {} base language fence)
  • indented or quoted

It also fixes those cases for the editor (both creation and edition).
The closing fence is automatically and properly set when you edit the opening fence.

The language string extraction (language and info string) should also be a bit faster because it's done in a single pass for each pattern instead of 3.

Sample

##### Tilde fence

~~~html
<strong>hello</strong>
~~~

##### Spaces after fence

``` html
<strong>hello</strong>
```

```  html
<strong>hello</strong>
```

##### More than 3 backticks

``````html
<strong>hello</strong>
``````

##### Additional instructions after language

```html something=true
<strong>hello</strong>
```

```html something=true other=info
<strong>hello</strong>
```

##### Fence without info

```
<strong>hello</strong>
```

##### Myst Code Directives

```{code} html
<strong>hello</strong>
```

```{code-block} html
<strong>hello</strong>
```

##### Myst Code Directive without language

```{code}
<strong>hello</strong>
```

```{code-cell}
<strong>hello</strong>
```

##### Quoted

> `````` python
> return "Hello"
> ``````

> ~~~~ python whatever
>  return "Hello World"
> ~~~~
Current main This PR
image image

Fixes #234

@noirbizarre
Copy link
Contributor Author

noirbizarre commented Jan 8, 2025

I've just seen your comment on #234, and so I just tried the dev branch (which is broken on my setup).
Anyway, I read the commit history and the changelog, it seems I handled some extra cases there.

Do you want me to port those extra cases fixes on dev (but I need to make it work on my setup first)? If not, feel free to pick whatever suits you in this PR.

Meanwhile, would it be possible to merge it on main until the next dev is released?

@OXY2DEV OXY2DEV merged commit 6e9f184 into OXY2DEV:main Jan 8, 2025
1 check passed
@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

it seems I handled some extra cases there.

I don't think we should handle every possible extra case.

The markdown parser itself has support for some of these extra cases, so we should rather use the (language) node for retrieving the language string.

OXY2DEV added a commit that referenced this pull request Jan 25, 2025
fix(code-blocks): Fixes multiple language parsing cases (tilde, spaces before/after, directives...)

feat(v25)!: New version release

- Completely rewritten `markview.nvim`
- Adds typst support
- Better rendering logic
- Performance optimizations.
- More customization

And more!
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.

🐞 Bug: Code blocks language parsing from info string only works for 3 backticks without spaces

2 participants