-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b23322a
commit 72735cb
Showing
8 changed files
with
98 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/app/features/article/articleViewer/highlightElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Element } from 'hast'; | ||
|
||
function genTitle(title: string) { | ||
return `可能存在的问题:${title}`; | ||
} | ||
|
||
export const Space: Element = { | ||
type: 'element', | ||
tagName: 'span', | ||
properties: { className: ['articleHighlight', 'Space'] }, | ||
children: [{ type: 'text', value: ' ' }] | ||
}; | ||
|
||
export const NeedSpaceBetweenEnglishCharAndChineseCharNote = | ||
'【中文】与【英文】字符间需要用空格隔开'; | ||
export const NeedSpaceBetweenEnglishCharAndChineseChar: Element = { | ||
type: 'element', | ||
tagName: 'span', | ||
properties: { | ||
className: [ | ||
'articleHighlight', | ||
'NeedSpaceBetweenPunctuationAndChineseChar' | ||
], | ||
title: genTitle(NeedSpaceBetweenEnglishCharAndChineseCharNote) | ||
}, | ||
children: [ | ||
{ | ||
type: 'element', | ||
tagName: 'div', | ||
properties: {}, | ||
children: [] | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { createElement, memo } from 'react'; | ||
import getProcessor from './getProcessor'; | ||
import * as HighlightElement from './highlightElement'; | ||
|
||
import 'katex/dist/katex.css'; | ||
import 'highlight.js/styles/base16/tomorrow.css'; | ||
import './style.css'; | ||
import './highlightFormatIssue.css'; | ||
|
||
const processor = getProcessor(); | ||
|
||
const ArticlerRenderer = memo( | ||
({ children: markdown }: { children: string }) => | ||
processor.processSync(markdown).result | ||
); | ||
|
||
export default function ArticleViewer({ | ||
markdown, | ||
addCommit | ||
}: { | ||
markdown: string; | ||
addCommit: (content: string) => void; | ||
}) { | ||
return ( | ||
<article | ||
onClick={e => { | ||
const target = e.target as HTMLElement; | ||
if ( | ||
target.parentElement?.classList.contains( | ||
'NeedSpaceBetweenPunctuationAndChineseChar' | ||
) | ||
) { | ||
addCommit( | ||
HighlightElement.NeedSpaceBetweenEnglishCharAndChineseCharNote | ||
); | ||
return; | ||
} | ||
}} | ||
> | ||
<ArticlerRenderer>{markdown}</ArticlerRenderer> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters