@abreen/tada 1.5.4 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ const log = makeLogger(import.meta.url);
11
11
  interface ApplyBasePathOptions {
12
12
  literateJavaOutputPaths?: Set<string>;
13
13
  sourceUrlPath?: string;
14
+ validTargets?: Set<string>;
14
15
  }
15
16
 
16
17
  export default function applyBasePathPlugin(
@@ -22,6 +23,7 @@ export default function applyBasePathPlugin(
22
23
  const rewriteCodeLinks = isFeatureEnabled(siteVariables, 'code');
23
24
  const literateJavaOutputPaths = pluginOptions.literateJavaOutputPaths;
24
25
  const sourceUrlPath = pluginOptions.sourceUrlPath;
26
+ const validTargets = pluginOptions.validTargets;
25
27
 
26
28
  function rewriteInternalHref(href: string): string {
27
29
  const match = href.match(/^([^?#]*)(.*)$/);
@@ -43,6 +45,19 @@ export default function applyBasePathPlugin(
43
45
  break;
44
46
  }
45
47
  }
48
+ // Only rewrite if the .html version exists. Public files with
49
+ // code extensions are copied as-is and have no .html page.
50
+ if (validTargets && sourceUrlPath) {
51
+ const resolved = modifiedPath.startsWith('/')
52
+ ? modifiedPath
53
+ : path.posix.join(
54
+ path.posix.dirname(sourceUrlPath),
55
+ modifiedPath,
56
+ );
57
+ if (!validTargets.has(`${resolved}.html`)) {
58
+ break;
59
+ }
60
+ }
46
61
  modifiedPath += '.html';
47
62
  break;
48
63
  }
@@ -25,6 +25,7 @@ interface CreateMarkdownOptions {
25
25
  validatorOptions?: Record<string, unknown>;
26
26
  literateJavaOutputPaths?: Set<string>;
27
27
  sourceUrlPath?: string;
28
+ validTargets?: Set<string>;
28
29
  }
29
30
 
30
31
  function capitalize(str: string): string {
@@ -43,6 +44,7 @@ export function createMarkdown(
43
44
  validatorOptions = {},
44
45
  literateJavaOutputPaths,
45
46
  sourceUrlPath,
47
+ validTargets,
46
48
  } = options;
47
49
  const markdown = new MarkdownIt({ html: true, typographer: true })
48
50
  .use(headingSubtitlePlugin)
@@ -55,6 +57,7 @@ export function createMarkdown(
55
57
  .use(applyBasePathPlugin, siteVariables, {
56
58
  literateJavaOutputPaths,
57
59
  sourceUrlPath,
60
+ validTargets,
58
61
  })
59
62
  .use(tocPlugin)
60
63
  .use(columnsPlugin)
@@ -125,7 +128,7 @@ export function createMarkdown(
125
128
  markdown.use(markdownItContainer, 'alert', {
126
129
  marker: '!',
127
130
  validate: function (params: string) {
128
- return !!params.trim().match(/^(note|warning)\s*"?(.+)?"?$/);
131
+ return !!params.trim().match(/^(note|warning)(?:\s+"(.+)"|\s+(.+))?$/);
129
132
  },
130
133
  render: function (
131
134
  tokens: Token[],
@@ -135,7 +138,7 @@ export function createMarkdown(
135
138
  ) {
136
139
  const matches = tokens[idx].info
137
140
  .trim()
138
- .match(/^(note|warning)\s*"?(.+)?"?$/);
141
+ .match(/^(note|warning)(?:\s+"(.+)"|\s+(.+))?$/);
139
142
 
140
143
  if (tokens[idx].nesting === 1) {
141
144
  const classNames = ['alert'];
@@ -144,7 +147,7 @@ export function createMarkdown(
144
147
  classNames.push(type);
145
148
  }
146
149
 
147
- const title = matches && matches[2]?.trim();
150
+ const title = matches && (matches[2] || matches[3])?.trim();
148
151
  const displayTitle = title
149
152
  ? markdown.utils.escapeHtml(curlyQuote(title))
150
153
  : capitalize(type || '');
@@ -377,6 +377,7 @@ function renderPlainTextContent(
377
377
  },
378
378
  literateJavaOutputPaths,
379
379
  sourceUrlPath,
380
+ validTargets: validInternalTargets,
380
381
  });
381
382
 
382
383
  const ext = path.extname(filePath);
@@ -559,6 +560,7 @@ export function renderLiterateJavaPageAsset({
559
560
  },
560
561
  literateJavaOutputPaths,
561
562
  sourceUrlPath,
563
+ validTargets: validInternalTargets,
562
564
  });
563
565
  let fenceIndex = 0;
564
566
  const defaultFence = md.renderer.rules.fence!;
@@ -150,6 +150,15 @@ export default function validateInternalLinks(
150
150
  }
151
151
 
152
152
  if (!validTargets!.has(resolvedPath)) {
153
+ // If code extension rewriting changed the path, check the original
154
+ // path too. Public files with code extensions are copied as-is and
155
+ // do not produce .html versions.
156
+ if (codeExtPattern) {
157
+ const unrewritten = resolveLinkPath(sourceUrlPath!, href, null);
158
+ if (unrewritten && validTargets!.has(unrewritten)) {
159
+ return;
160
+ }
161
+ }
153
162
  reportBrokenLink(rawHref, resolvedPath);
154
163
  }
155
164
  }
@@ -0,0 +1,9 @@
1
+ /// A source code file which is simply copied into the built site.
2
+ /// Tada will not process this file: it won't create an HTML file for it
3
+ /// (even if `features.code` is `true`) and it won't appear in search results
4
+ /// (even if `features.search` is `true`).
5
+ public class Test {
6
+ public static void main(String[] args) {
7
+ System.out.println("hello");
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abreen/tada",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "type": "module",
5
5
  "description": "A static site generator",
6
6
  "license": "MIT",