Commit 6388f4a 1 parent cdb4a7e commit 6388f4a Copy full SHA for 6388f4a
File tree 2 files changed +36
-0
lines changed
tests/unit/pandoc-codegen
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,23 @@ export function pandocBlock(delimiterCharacter: ":" | "`") {
232
232
} ;
233
233
}
234
234
235
+ export function pandocNativeStr ( content : string ) : PandocNode {
236
+ return {
237
+ ...basePandocNode ,
238
+ emit : ( ls : EitherString [ ] ) => {
239
+ const maxBackticks = content . match ( / ` + / g) ?. [ 0 ] . length || 0 ;
240
+ const backticks = "`" . repeat ( maxBackticks + 1 ) ;
241
+ const escapedContent = content . replaceAll (
242
+ '"' ,
243
+ '\\"' ,
244
+ ) ;
245
+ ls . push (
246
+ `${ backticks } ${ 'Str "' } ${ escapedContent } ${ '"' } ${ backticks } {=pandoc-native}` ,
247
+ ) ;
248
+ } ,
249
+ } ;
250
+ }
251
+
235
252
export const pandocDiv = pandocBlock ( ":" ) ;
236
253
export const pandocCode = pandocBlock ( "`" ) ;
237
254
export const pandocFigure = pandocHtmlBlock ( "figure" ) ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * native-string.test.ts
3
+ *
4
+ * Copyright (C) 2021-2022 Posit Software, PBC
5
+ *
6
+ */
7
+
8
+ import bounds from "binary-search-bounds" ;
9
+
10
+ import { unitTest } from "../../test.ts" ;
11
+ import { assert } from "testing/asserts.ts" ;
12
+ import { pandocNativeStr } from "../../../src/core/pandoc/codegen.ts" ;
13
+
14
+ // deno-lint-ignore require-await
15
+ unitTest ( "native-string - basics" , async ( ) => {
16
+ assert ( pandocNativeStr ( "hello" ) . mappedString ( ) . value === '`Str "hello"`{=pandoc-native}' ) ;
17
+ assert ( pandocNativeStr ( '"hello"' ) . mappedString ( ) . value === '`Str "\\"hello\\""`{=pandoc-native}' ) ;
18
+ assert ( pandocNativeStr ( '"hel`lo"' ) . mappedString ( ) . value === '``Str "\\"hel`lo\\""``{=pandoc-native}' ) ;
19
+ } )
You can’t perform that action at this time.
0 commit comments