File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
import type { InlinePlugin } from "../types.ts" ;
2
- import { escape } from "@dbushell/hyperless" ;
2
+ import { escape , unescape } from "@dbushell/hyperless" ;
3
3
4
4
const REGEXP = / ` ( [ ^ ` ] + ) ` / g;
5
5
6
6
const plugin : InlinePlugin = {
7
7
type : "code" ,
8
8
prerender : ( text : string ) => {
9
- if ( text . includes ( "`" ) === false ) return text ;
9
+ if ( text . indexOf ( "`" ) === - 1 ) return text ;
10
10
// Inline code is escaped early to avoid `<div>` being parsed as HTML node
11
- return text . replace ( REGEXP , ( ...match ) => escape ( match [ 0 ] ) ) ;
11
+ return text . replace ( REGEXP , ( ...match ) => {
12
+ const text = unescape ( match [ 0 ] ) ;
13
+ return escape ( text ) ;
14
+ } ) ;
12
15
} ,
13
16
render : ( text : string ) => {
14
17
text = text . replace ( REGEXP , ( ...match ) => `<code>${ match [ 1 ] } </code>` ) ;
Original file line number Diff line number Diff line change @@ -25,3 +25,8 @@ Deno.test("code (anchor inception)", async () => {
25
25
"<p><code>This [emoji] 🍋🟩 is a [lime](https://emojipedia.org/lime) ok?</code></p>" ,
26
26
) ;
27
27
} ) ;
28
+
29
+ Deno . test ( "code (html)" , async ( ) => {
30
+ const html = await hmmarkdown ( "<div>`</div>`</div>" ) ;
31
+ assertEquals ( html , "<div><p><code></div></code></p></div>" ) ;
32
+ } ) ;
You can’t perform that action at this time.
0 commit comments