mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(markdown): allow repeated greentext markers
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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} />;
|
||||
|
||||
Reference in New Issue
Block a user