Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 proposed aligned paragraph tokens #3908

Merged
merged 21 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
929469d
Working feature.
dbolacksn Nov 23, 2024
440ad51
Add justification token testing
dbolacksn Nov 23, 2024
deb9c66
Add Styles for Forced Justifcation Tokens
dbolacksn Nov 23, 2024
b7cb6dc
Merge branch 'master' into justifiedParagraphs
dbolacksn Dec 5, 2024
f4c2605
Merge branch 'master' into justifiedParagraphs
dbolacksn Dec 11, 2024
89bd082
Shift alignment assignment from CSS to HTML
dbolacksn Dec 11, 2024
7c69d2a
Update tests to match
dbolacksn Dec 11, 2024
f9b42a3
Merge branch 'master' into justifiedParagraphs
dbolacksn Dec 18, 2024
08b0f47
Fix Regex for Justified paragraphs
dbolacksn Dec 18, 2024
99d3d28
Correct end of match criteria for justified paragraph to account for …
dbolacksn Dec 18, 2024
f71850d
Merge branch 'master' into justifiedParagraphs
dbolacksn Dec 20, 2024
90632b7
Add direct tests for paragraph justification
dbolacksn Dec 20, 2024
79c8309
Add circleci
dbolacksn Dec 21, 2024
26c9406
Merge branch 'master' into justifiedParagraphs
dbolacksn Dec 28, 2024
d75db5d
Merge branch 'master' into justifiedParagraphs
dbolacksn Jan 12, 2025
4958ade
Remove V4 cruft that should never have been merged
dbolacksn Jan 14, 2025
3c735e5
Add a CR
dbolacksn Jan 14, 2025
20bfff5
Remove it back? Meh. Just trying to revert to last
dbolacksn Jan 14, 2025
b91f18a
Merge branch 'master' into justifiedParagraphs
dbolacksn Jan 14, 2025
3e5a72f
Merge branch 'master' into justifiedParagraphs
dbolacksn Jan 15, 2025
f7b36a9
Merge branch 'master' into justifiedParagraphs
5e-Cleric Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ jobs:
- run:
name: Test - Non-Breaking Spaces
command: npm run test:non-breaking-spaces
- run:
name: Test - Paragraph Justification
command: npm run test:paragraph-justification
- run:
name: Test - Variables
command: npm run test:variables
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test:definition-lists": "jest tests/markdown/definition-lists.test.js --verbose --noStackTrace",
"test:hard-breaks": "jest tests/markdown/hard-breaks.test.js --verbose --noStackTrace",
"test:non-breaking-spaces": "jest tests/markdown/non-breaking-spaces.test.js --verbose --noStackTrace",
"test:paragraph-justification": "jest tests/markdown/paragraph-justification.test.js --verbose --noStackTrace",
"test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace",
"test:route": "jest tests/routes/static-pages.test.js --verbose",
"test:safehtml": "jest tests/html/safeHTML.test.js --verbose",
Expand Down
39 changes: 38 additions & 1 deletion shared/naturalcrit/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,43 @@ const superSubScripts = {
}
};


const justifiedParagraphClasses = [];
justifiedParagraphClasses[2] = 'Left';
justifiedParagraphClasses[4] = 'Right';
justifiedParagraphClasses[6] = 'Center';

const justifiedParagraphs = {
name : 'justifiedParagraphs',
level : 'block',
start(src) {
return src.match(/\n(?:-:|:-|-:) {1}/m)?.index;
}, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const regex = /^(((:-))|((-:))|((:-:))) .+(\n(([^\n].*\n)*(\n|$))|$)/ygm;
const match = regex.exec(src);
if(match?.length) {
let whichJustify;
if(match[2]?.length) whichJustify = 2;
if(match[4]?.length) whichJustify = 4;
if(match[6]?.length) whichJustify = 6;
return {
type : 'justifiedParagraphs', // Should match "name" above
raw : match[0], // Text to consume from the source
length : match[whichJustify].length,
text : match[0].slice(match[whichJustify].length),
class : justifiedParagraphClasses[whichJustify],
tokens : this.lexer.inlineTokens(match[0].slice(match[whichJustify].length + 1))
};
}
},
renderer(token) {
return `<p align="${token.class}">${this.parser.parseInline(token.tokens)}</p>`;
}

};


const forcedParagraphBreaks = {
name : 'hardBreaks',
level : 'block',
Expand Down Expand Up @@ -768,7 +805,7 @@ const tableTerminators = [
];

Marked.use(MarkedVariables());
Marked.use({ extensions : [definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
nonbreakingSpaces, superSubScripts, mustacheSpans, mustacheDivs, mustacheInjectInline] });
Marked.use(mustacheInjectBlock);
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
Expand Down
27 changes: 27 additions & 0 deletions tests/markdown/paragraph-justification.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable max-lines */

import Markdown from 'naturalcrit/markdown.js';

describe('Justification', ()=>{
test('Left Justify', function() {
const source = ':- Hello';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p align=\"Left\">Hello</p>`);
});
test('Right Justify', function() {
const source = '-: Hello';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p align=\"Right\">Hello</p>`);
});
test('Center Justify', function() {
const source = ':-: Hello';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<p align=\"Center\">Hello</p>`);
});

test('Ignored inside a code block', function() {
const source = '```\n\n:- Hello\n\n```\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`<pre><code>\n:- Hello\n</code></pre>\n`);
});
});
2 changes: 1 addition & 1 deletion themes/V3/Blank/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,4 @@ body { counter-reset : page-numbers 0; }
counter-increment : page-numbers;
}

}
}