-
Notifications
You must be signed in to change notification settings - Fork 11
fix: embeds and images save better #893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3f7f9c1
5371d1d
ef1c17b
394ebbc
d4b0ff2
048716f
fe91aea
358741b
ab7f718
89afef1
ec3f201
c3442d8
b00921a
fa0a549
05c182b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
coverage | ||
node_modules | ||
|
||
.env | ||
.idea/ | ||
.vscode/ | ||
*.code-* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { mdast } from '../index'; | ||
|
||
describe.skip('Parse html block', () => { | ||
describe('Parse html block', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
it('parses an html block', () => { | ||
const text = ` | ||
<div>Some block html</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
export enum NodeTypes { | ||
callout = 'rdme-callout', | ||
codeTabs = 'code-tabs', | ||
embed = 'embed', | ||
embedBlock = 'embed-block', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a regular embed block still? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, no. i changed the structure enough that the serializing/deserializing was getting to be spaghetti with the current/old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it also allows me more freedom to dial in the new image and embed blocks, haha |
||
emoji = 'gemoji', | ||
glossary = 'readme-glossary-item', | ||
htmlBlock = 'html-block', | ||
i = 'i', | ||
image = 'image', | ||
imageBlock = 'image-block', | ||
reusableContent = 'reusable-content', | ||
tutorialTile = 'tutorial-tile', | ||
variable = 'readme-variable', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import type { Embed } from "types"; | ||
import { formatHProps, getHProps } from "../utils"; | ||
import type { EmbedBlock } from "types"; | ||
|
||
const embed = (node: Embed) => { | ||
const { image, favicon, iframe, title, url } = node.data?.hProperties || {}; | ||
const complexEmbed: boolean = Boolean(image) || Boolean(favicon) || iframe; | ||
const embed = (node: EmbedBlock) => { | ||
const attributes = formatHProps<EmbedBlock['data']['hProperties']>(node) | ||
const props = getHProps<EmbedBlock['data']['hProperties']>(node); | ||
|
||
if (complexEmbed) { | ||
const attributes = Object.keys(node.data?.hProperties).map(key => `${key}="${node.data?.hProperties[key]}"`).join(' ') | ||
// TODO: make this a util | ||
return `<Embed ${attributes} />`; | ||
} | ||
if (node.title !== '@embed') { | ||
return `<Embed ${attributes} />` | ||
kellyjosephprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
return `[${title}](${url} "@embed")'`; | ||
return `[${node.label || ''}](${props.url} "${node.title}")` | ||
} | ||
|
||
export default embed; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import type { Image } from 'mdast'; | ||
import type { ImageBlock } from 'types'; | ||
import { formatHProps, getHPropKeys, getHProps } from '../utils'; | ||
|
||
const image = (node: Image) => { | ||
const { align, className, width } = node.data?.hProperties || {}; | ||
const complexImage: boolean = Boolean(width) || Boolean(className) || Boolean(align); | ||
const image = (node: ImageBlock) => { | ||
const attributes = formatHProps<ImageBlock['data']['hProperties']>(node); | ||
const hProps = getHProps<ImageBlock['data']['hProperties']>(node); | ||
const hPropKeys = getHPropKeys<string[]>(node); | ||
|
||
const ImageBlock = `<Image ${attributes} />`; | ||
const MDImage = `` : ')'}`; | ||
|
||
if (complexImage) { | ||
const attributes = Object.keys(node.data?.hProperties) | ||
.map(key => `${key}="${node.data?.hProperties[key]}"`) | ||
.join(' '); | ||
return `<Image ${attributes} />`; | ||
if (Boolean(attributes)) { | ||
if (hPropKeys.includes('src') && (hPropKeys.includes('width') || hPropKeys.includes('border') || hPropKeys.includes('align'))) { | ||
return ImageBlock; | ||
} | ||
} | ||
|
||
return `` : ')'}`; | ||
}; | ||
return MDImage; | ||
} | ||
|
||
export default image; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hee hee