mirror of
https://github.com/marktext/marktext.git
synced 2025-05-07 11:50:52 +08:00

* support ruby and better raw html display * finish ruby render * add kbd style * if content is empty string, do not hide tag * update changelog * add auto complement to inline html * opti slit words * opti tool bar style * support open inline a tag if it is a external link * fix: auto complete * add attribute white list * add comment * delete some commented codes
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import { CLASS_OR_ID } from '../../../config'
|
|
import { getImageInfo } from '../../../utils'
|
|
|
|
// html_image
|
|
export default function htmlImage (h, cursor, block, token, outerClass) {
|
|
const className = this.getClassName(outerClass, block, token, cursor)
|
|
const imageClass = CLASS_OR_ID['AG_IMAGE_MARKED_TEXT']
|
|
const { start, end } = token.range
|
|
const tag = this.highlight(h, block, start, end, token)
|
|
const { src: rawSrc, alt = '', width, height } = token.attrs
|
|
const imageInfo = getImageInfo(rawSrc)
|
|
const { src } = imageInfo
|
|
let id
|
|
let isSuccess
|
|
let selector
|
|
if (src) {
|
|
({ id, isSuccess } = this.loadImageAsync(imageInfo, alt, className, CLASS_OR_ID['AG_COPY_REMOVE']))
|
|
}
|
|
selector = id ? `span#${id}.${imageClass}.${CLASS_OR_ID['AG_HTML_TAG']}` : `span.${imageClass}.${CLASS_OR_ID['AG_HTML_TAG']}`
|
|
selector += `.${CLASS_OR_ID['AG_OUTPUT_REMOVE']}`
|
|
if (isSuccess) {
|
|
selector += `.${className}`
|
|
} else {
|
|
selector += `.${CLASS_OR_ID['AG_IMAGE_FAIL']}`
|
|
}
|
|
const props = { alt, src }
|
|
if (typeof width === 'number') {
|
|
props.width = width
|
|
}
|
|
if (typeof height === 'number') {
|
|
props.height = height
|
|
}
|
|
return isSuccess
|
|
? [
|
|
h(selector, tag),
|
|
h(`img.${CLASS_OR_ID['AG_COPY_REMOVE']}`, { props })
|
|
]
|
|
: [h(selector, tag)]
|
|
}
|