summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/tokenizer.ts
diff options
context:
space:
mode:
authorGravatar bholmesdev <bholmesdev@users.noreply.github.com> 2023-07-24 23:36:32 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2023-07-24 23:36:32 +0000
commit25e04a2ecbda7952a68220ce6739ae1c75144858 (patch)
tree1fc602a9a1cef5bb9cde6b3d3c8465f7129cbb90 /packages/integrations/markdoc/src/tokenizer.ts
parent7461e82c81438df956861197536f9ceeaf63d6b3 (diff)
downloadastro-25e04a2ecbda7952a68220ce6739ae1c75144858.tar.gz
astro-25e04a2ecbda7952a68220ce6739ae1c75144858.tar.zst
astro-25e04a2ecbda7952a68220ce6739ae1c75144858.zip
[ci] format
Diffstat (limited to 'packages/integrations/markdoc/src/tokenizer.ts')
-rw-r--r--packages/integrations/markdoc/src/tokenizer.ts46
1 files changed, 22 insertions, 24 deletions
diff --git a/packages/integrations/markdoc/src/tokenizer.ts b/packages/integrations/markdoc/src/tokenizer.ts
index 11135c18e..02719b363 100644
--- a/packages/integrations/markdoc/src/tokenizer.ts
+++ b/packages/integrations/markdoc/src/tokenizer.ts
@@ -5,34 +5,32 @@ import type { MarkdocIntegrationOptions } from './options.js';
type TokenizerOptions = ConstructorParameters<typeof Tokenizer>[0];
export function getMarkdocTokenizer(options: MarkdocIntegrationOptions | undefined): Tokenizer {
-
- const key = cacheKey(options);
-
- if (!_cachedMarkdocTokenizers[key]) {
-
- const tokenizerOptions: TokenizerOptions = {
- // Strip <!-- comments --> from rendered output
- // Without this, they're rendered as strings!
- allowComments: true,
- }
-
- if (options?.allowHTML) {
- // we want to allow indentation for Markdoc tags that are interleaved inside HTML block elements
- tokenizerOptions.allowIndentation = true;
- // enable HTML token detection in markdown-it
- tokenizerOptions.html = true;
- }
-
- _cachedMarkdocTokenizers[key] = new Markdoc.Tokenizer(tokenizerOptions);
- }
-
- return _cachedMarkdocTokenizers[key];
-};
+ const key = cacheKey(options);
+
+ if (!_cachedMarkdocTokenizers[key]) {
+ const tokenizerOptions: TokenizerOptions = {
+ // Strip <!-- comments --> from rendered output
+ // Without this, they're rendered as strings!
+ allowComments: true,
+ };
+
+ if (options?.allowHTML) {
+ // we want to allow indentation for Markdoc tags that are interleaved inside HTML block elements
+ tokenizerOptions.allowIndentation = true;
+ // enable HTML token detection in markdown-it
+ tokenizerOptions.html = true;
+ }
+
+ _cachedMarkdocTokenizers[key] = new Markdoc.Tokenizer(tokenizerOptions);
+ }
+
+ return _cachedMarkdocTokenizers[key];
+}
// create this on-demand when needed since it relies on the runtime MarkdocIntegrationOptions and may change during
// the life of module in certain scenarios (unit tests, etc.)
let _cachedMarkdocTokenizers: Record<string, Tokenizer> = {};
function cacheKey(options: MarkdocIntegrationOptions | undefined): string {
- return JSON.stringify(options);
+ return JSON.stringify(options);
}