Skip to content

Commit

Permalink
Rename defaultSyntaxLanguage to defaultCodeDirectiveLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes committed Aug 14, 2024
1 parent fa16f5f commit f83801b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/Generator/RstGeneratorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ export type RstGeneratorOptions = {
defaultLiteralBlockLanguage: string

/**
* Default language for syntax highlighting in `code` and `code-block` Directive
* Default language for syntax highlighting in `code` and `code-block` Directives
*
* Default: `''`
* Default: `'txt'`
*/
defaultSyntaxLanguage: string
defaultCodeDirectiveLanguage: string

/**
* ### HTML ONLY
*
* Options for syntax highlighting with shiki
* Options for syntax highlighting `code` and `code-block` Directives with shiki
*
* If not set, code blocks will output as `<pre>` and inline code will output as `<code>`
* If not set, `code` and `code-block` Directives will output code inside plain `<pre>`
*/
shiki?: {
highlighter: Awaited<ReturnType<typeof createHighlighter>>
Expand Down Expand Up @@ -166,7 +166,7 @@ export function createDefaultGeneratorOptions(opts?: Partial<RstGeneratorOptions
} satisfies Required<RstGeneratorOptions['htmlClass']>,

defaultLiteralBlockLanguage: 'txt',
defaultSyntaxLanguage: '',
defaultCodeDirectiveLanguage: 'txt',

directivesWillOutputMdContainers: [],
}
Expand Down
8 changes: 4 additions & 4 deletions src/Plugins/Code/CodePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const highlightDirectiveGenerators = createDirectiveGenerators(

(generatorState, node) => {
generatorState.opts.defaultLiteralBlockLanguage = node.initContentText
generatorState.opts.defaultSyntaxLanguage = node.initContentText
generatorState.opts.defaultCodeDirectiveLanguage = node.initContentText
generatorState.writeLineHtmlComment(node.toShortString())
},

(generatorState, node) => {
generatorState.opts.defaultLiteralBlockLanguage = node.initContentText
generatorState.opts.defaultSyntaxLanguage = node.initContentText
generatorState.opts.defaultCodeDirectiveLanguage = node.initContentText
generatorState.writeLineMdComment(node.toShortString())
},
)
Expand All @@ -34,12 +34,12 @@ export const codeDirectiveGenerators = createDirectiveGenerators(
],

(generatorState, node) => {
const language = getCodeLanguage(node) ?? generatorState.opts.defaultSyntaxLanguage
const language = getCodeLanguage(node) ?? generatorState.opts.defaultCodeDirectiveLanguage
renderCodeBlockHtml(generatorState, language, node.rawBodyText, node)
},

(generatorState, node) => {
const language = getCodeLanguage(node) ?? generatorState.opts.defaultSyntaxLanguage
const language = getCodeLanguage(node) ?? generatorState.opts.defaultCodeDirectiveLanguage
renderCodeBlockMd(generatorState, language, node.rawBodyText)
},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/playground/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Bun.serve({
const dirname = path.dirname(filename)
const rst = fs.readFileSync(path.join(dirname, 'playground.rst')).toString('utf-8')
const { body, header } = new RstToHtmlCompiler().compile(rst, {}, {
defaultSyntaxLanguage: 'python',
defaultCodeDirectiveLanguage: 'python',
shiki: {
theme: 'github-light',
highlighter: await createHighlighter({
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Plugins/Code/CodePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('highlight Directive changes default language of code Directive', () =>
<pre class="code">text 2</pre>
`, `
\`\`\`
\`\`\`txt
text 1
\`\`\`
Expand Down

0 comments on commit f83801b

Please sign in to comment.