Skip to content

Commit

Permalink
Add generator option to specify default LiteralBlock language
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes committed Jun 29, 2024
1 parent f253428 commit 5705e3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Generator/RstGeneratorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export type RstGeneratorOptions = {
opts: KatexOptions
}

/**
* Default language for syntax highlighting LiteralBlock
*
* Default: `'txt'`
*/
defaultLiteralBlockLanguage: string

/**
* Default language for syntax highlighting
*
Expand Down Expand Up @@ -149,6 +156,7 @@ export function createDefaultGeneratorOptions(opts?: Partial<RstGeneratorOptions
tocTree: 'toc-tree',
} satisfies Required<RstGeneratorOptions['htmlClass']>,

defaultLiteralBlockLanguage: 'txt',
defaultSyntaxLanguage: '',
} satisfies RstGeneratorOptions, opts)
}
6 changes: 4 additions & 2 deletions src/RstNode/Block/LiteralBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ export const literalBlockGenerators = createNodeGenerators(

(generatorState, node) => {
generatorState.writeLineHtmlTagWithAttr('div', node, new HtmlAttributeStore({ class: generatorState.opts.htmlClass.literalBlock }), () => {
renderCodeBlockHtml(generatorState, 'txt', node.rawTextContent, node)
const language = generatorState.opts.defaultLiteralBlockLanguage
renderCodeBlockHtml(generatorState, language, node.rawTextContent, node)
})
},

(generatorState, node) => {
renderCodeBlockMd(generatorState, 'txt', node.rawTextContent)
const language = generatorState.opts.defaultLiteralBlockLanguage
renderCodeBlockMd(generatorState, language, node.rawTextContent)
},
)

0 comments on commit 5705e3b

Please sign in to comment.