mirror of
https://github.com/harness/drone.git
synced 2025-05-03 14:10:05 +00:00
fix: [code-421]: addressed tans comment
This commit is contained in:
parent
742beda319
commit
b1d65bb27a
@ -21,16 +21,13 @@ export function MarkdownViewer({ source, className, maxHeight }: MarkdownViewerP
|
|||||||
const [zoomLevel, setZoomLevel] = useState(INITIAL_ZOOM_LEVEL)
|
const [zoomLevel, setZoomLevel] = useState(INITIAL_ZOOM_LEVEL)
|
||||||
const [imgEvent, setImageEvent] = useState<string[]>([])
|
const [imgEvent, setImageEvent] = useState<string[]>([])
|
||||||
const refRootHref = useMemo(() => document.getElementById('repository-ref-root')?.getAttribute('href'), [])
|
const refRootHref = useMemo(() => document.getElementById('repository-ref-root')?.getAttribute('href'), [])
|
||||||
|
|
||||||
const interceptClickEventOnViewerContainer = useCallback(
|
const interceptClickEventOnViewerContainer = useCallback(
|
||||||
event => {
|
event => {
|
||||||
|
const imgTags = document.querySelectorAll('img');
|
||||||
const { target } = event
|
const { target } = event
|
||||||
const imgPattern = /!\[.*?\]\((.*?)\)/;
|
const imageArray= Array.from(imgTags)
|
||||||
const imageArray = source.split('\n').filter(string => imgPattern.test(string))
|
const imageStringArray= imageArray.filter(object=>object.src && !object.className).map(img=>img.src)
|
||||||
const imageStringArray = imageArray.map(string => {
|
|
||||||
const match = string.match(imgPattern);
|
|
||||||
return match ? match[1] : '';
|
|
||||||
})
|
|
||||||
|
|
||||||
setImageEvent(imageStringArray)
|
setImageEvent(imageStringArray)
|
||||||
|
|
||||||
if (target?.tagName?.toLowerCase() === 'a') {
|
if (target?.tagName?.toLowerCase() === 'a') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user