fix(markdown): allow repeated greentext markers

This commit is contained in:
Tommaso Casaburi
2026-05-11 14:33:00 +07:00
parent 618aa97799
commit 719005e935
2 changed files with 18 additions and 1 deletions
@@ -230,6 +230,17 @@ describe('Markdown', () => {
expect(links.find((link) => link.getAttribute('href') === '/fit')?.textContent).toBe('>>>/fit/');
});
it('renders greentext for any leading marker run while preserving quote links', async () => {
await renderMarkdown({
content: '>green line\n>>test\n>>>>>>>test\n>>42\n>>>/fit/',
communityAddress: 'music-posting.eth',
});
expect(Array.from(container.querySelectorAll('.greentext')).map((node) => node.textContent)).toEqual(['>green line', '>>test', '>>>>>>>test']);
expect(container.querySelector('[data-testid="external-number-quote-link"]')?.textContent).toBe('>>42');
expect(Array.from(container.querySelectorAll('a')).find((link) => link.getAttribute('href') === '/fit')?.textContent).toBe('>>>/fit/');
});
it('preserves trailing punctuation outside cross-board links', async () => {
await renderMarkdown({
content: 'see >>>/fit/, next',
+7 -1
View File
@@ -160,6 +160,12 @@ const COMBINED_REGEX = new RegExp(
const makeTokenKey = (prefix: string, type: Token['type'], start: number, end: number): string => `${prefix}${type}:${start}:${end}`;
const isGreentextLine = (line: string): boolean => {
if (line === '>') return true;
if (!/^>+[^>]/.test(line)) return false;
return !/^>>\d/.test(line) && !line.startsWith('>>>/');
};
function normalizeInternalRouteHref(href: string): string {
if (href.startsWith('/#/')) {
return href.slice(2);
@@ -458,7 +464,7 @@ const Markdown = ({ content, title, postCid, communityAddress }: MarkdownProps)
if (line.length === 0) return;
const isGreentext = /^>[^>]/.test(line) || line === '>';
const isGreentext = isGreentextLine(line);
const tokens = tokenize(line);
const lineElements = <TokenList tokens={tokens} context={context} />;