Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
added width to image markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
iskaktoltay committed Aug 22, 2024
1 parent 7218019 commit 3b9de52
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion frontend/packages/app/utils/blocks-to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ function convertBlockToHtml(block, isListItem = false) {
case 'paragraph':
return `<p>${contentHtml}</p>`
case 'image':
return `<img src="${block.props.url}" alt="${contentHtml}" title="${block.props.name}">`
const {url, name, width} = block.props
const titleWithWidth = `${name} | width=${width}`
return `<img src="${url}" alt="${contentHtml}" title="${titleWithWidth}">`
case 'codeBlock':
return `<pre><code class="language-${
block.props.language || 'plaintext'
Expand Down Expand Up @@ -133,9 +135,29 @@ export async function convertBlocksToMarkdown(blocks: HMBlock[]) {
const markdownFile = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypeRemark)
// .use(addImageWidth)
.use(remarkGfm)
.use(remarkStringify)
.process(convertBlocksToHtml(blocks))
const markdownContent = markdownFile.value as string
return {markdownContent, mediaFiles}
}

// import {visit} from 'unist-util-visit'

// function addImageWidth() {
// return (tree) => {
// visit(tree, 'image', (node) => {
// console.log(node)
// const width = node.width
// console.log(width)

// if (width) {
// // Inject width into the title attribute
// node.title = node.title
// ? `${node.title} "width=${width}"`
// : `"width=${width}"`
// }
// })
// }
// }

0 comments on commit 3b9de52

Please sign in to comment.