')]);
+ expect(html.unshown()).to.equal(2);
+ });
+
+ it('cuts a long piece short', () => {
+ const html = new LeftOutHtml(index, [piece(5, `${'word '.repeat(20)}
`), piece(9, '
')]);
+
+ expect(html.shown()).to.deep.equal([piece(5, `${'word '.repeat(8)}w…`), piece(9, '
')]);
+ });
+
+ it('leaves nothing unshown on a page with three pieces or fewer', () => {
+ expect(new LeftOutHtml(index, [piece(5, '
'), piece(9, '
')]).unshown()).to.equal(0);
+ });
+
+ it('adds nothing to the same page holding the same pieces, wherever they now are', () => {
+ const before = new LeftOutHtml(index, [piece(5, '
'), piece(9, '')]);
+
+ expect(new LeftOutHtml(index, [piece(7, '
'), piece(12, '
')]).addsNothingTo(before)).to.be.true;
+ expect(new LeftOutHtml(index, [piece(7, '
'), piece(14, '')]).addsNothingTo(before)).to.be.false;
+ expect(new LeftOutHtml(intro, [piece(5, '
')]).addsNothingTo(before)).to.be.false;
+ });
+});
diff --git a/test/types/portal/page.test.ts b/test/types/portal/page.test.ts
index d4fbf7a9..a975fae2 100644
--- a/test/types/portal/page.test.ts
+++ b/test/types/portal/page.test.ts
@@ -182,4 +182,49 @@ describe('parsePage', () => {
expect(await images('
\n\nInline
here.\n')).to.deep.equal([]);
});
});
+
+ // The build leaves out every piece of HTML in a `.md` page, and the reader loses what it says.
+ describe('the HTML of a .md page', () => {
+ const html = async (markdown: string, name?: string) => (await page(markdown, name)).leftOutHtml;
+
+ it('names each piece of HTML by the line it starts on, as written', async () => {
+ const markdown =
+ '---\ntitle: Tags\n---\n\nLine one
line two.\n\n\nMore
\n\nHidden.\n\n' +
+ ' \n\n\nKeep it secret.\n\n';
+
+ expect(await html(markdown)).to.deep.equal([
+ { line: 5, text: '
' },
+ { line: 7, text: '' },
+ { line: 14, text: '' }
+ ]);
+ });
+
+ it('names a piece that leaves text out after a closing tag or a comment', async () => {
+ const markdown =
+ '\nThis line is left out too.\n\n And this one.\n\n After an empty comment\n';
+
+ expect(await html(markdown)).to.deep.equal([
+ { line: 1, text: '' },
+ { line: 4, text: ' And this one.' },
+ { line: 6, text: ' After an empty comment' }
+ ]);
+ });
+
+ it('leaves out a piece of nothing but comments and closing tags', async () => {
+ const markdown =
+ '\n\nText here.\n\n \n\nPress Ctrl.\n\n\n';
+
+ expect(await html(markdown)).to.deep.equal([{ line: 7, text: '' }]);
+ });
+
+ it('reads code, inline code and an autolink as the text they are', async () => {
+ const markdown = '```html\n\n```\n\nWrite `
` for a break, or see .\n';
+
+ expect(await html(markdown)).to.deep.equal([]);
+ });
+
+ it('names none in an .mdx page, which renders its HTML', async () => {
+ expect(await html('Line one
line two.\n\n\n\nText.\n\n \n', 'page.mdx')).to.deep.equal([]);
+ });
+ });
});
diff --git a/test/types/portal/preview-content.test.ts b/test/types/portal/preview-content.test.ts
index 9031268c..645fb0ce 100644
--- a/test/types/portal/preview-content.test.ts
+++ b/test/types/portal/preview-content.test.ts
@@ -4,6 +4,7 @@ import { FileName } from '../../../src/types/file/fileName';
import { FilePath } from '../../../src/types/file/filePath';
import { ContentNotices } from '../../../src/types/portal/content-notices';
import { GeneratedSection, PLUGIN_SECTION, SDK_SECTION } from '../../../src/types/portal/generated-pages';
+import { LeftOutHtml } from '../../../src/types/portal/left-out-html';
import { TabEntry } from '../../../src/types/portal/portal-navigation';
import { PortalTab, SharedTabName } from '../../../src/types/portal/portal-tabs';
import { PreviewContent } from '../../../src/types/portal/preview-content';
@@ -14,6 +15,7 @@ describe('PreviewContent', () => {
const folder = (name: string) => content.join(name);
const NONE: ContentNotices = {
+ leftOutHtml: [],
hiddenPages: [],
ignoredNavigationFiles: [],
sharedTabNames: [],
@@ -114,6 +116,23 @@ describe('PreviewContent', () => {
expect(noticesAfter(titled, titled).unseenHomeTitle).to.be.undefined;
});
+ it('gives the left-out HTML again when a page has a piece it did not have, not when one moves', () => {
+ const index = new FilePath(content, new FileName('index.md'));
+ const before = notices({ leftOutHtml: [new LeftOutHtml(index, [{ line: 5, text: '
' }])] });
+ const moved = notices({ leftOutHtml: [new LeftOutHtml(index, [{ line: 9, text: '
' }])] });
+ const added = notices({
+ leftOutHtml: [
+ new LeftOutHtml(index, [
+ { line: 9, text: '
' },
+ { line: 14, text: '' }
+ ])
+ ]
+ });
+
+ expect(noticesAfter(moved, before).leftOutHtml).to.deep.equal([]);
+ expect(noticesAfter(added, before).leftOutHtml).to.deep.equal(added.leftOutHtml);
+ });
+
it('gives a name shared by another tab than before', () => {
const sdks: PortalTab = { owner: { kind: 'generated', section: SDK_SECTION }, name: 'Guides', namedBy: null };
const plugin: PortalTab = { owner: { kind: 'generated', section: PLUGIN_SECTION }, name: 'Guides', namedBy: null };