Skip to content

Commit

Permalink
chore: always show meta
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed May 8, 2023
1 parent 7ae75bd commit dc9d845
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ export function importMarkdownToLexical(
mdastExtensions: [mdxFromMarkdown(), frontmatterFromMarkdown('yaml'), directiveFromMarkdown],
})

// add a frontmatter node if there is none
if (tree.children[0].type !== 'yaml') {
tree.children.unshift({ type: 'yaml', value: '' })
}

function visitChildren(mdastNode: Mdast.Parent, lexicalParent: LexicalNode) {
if (!isParent(mdastNode)) {
throw new Error('Attempting to visit children of a non-parent')
Expand Down Expand Up @@ -326,10 +331,5 @@ export const UsedLexicalNodes = [
FrontmatterNode,
AdmonitionNode,
JsxNode,
{
replace: CodeNode,
with: (node: CodeNode) => {
return new CodeBlockNode('Replaced?', 'js', '')
},
},
CodeNode, // this one should not be used, but markdown shortcuts complain about it
]
2 changes: 1 addition & 1 deletion src/ui/NodeDecorators/CodeBlockEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const CodeBlockEditor = ({ nodeKey, code, language, onChange, focusEmitte

const wrappedOnChange = React.useCallback(
(code: string) => {
activeEditor.update(() => {
activeEditor?.update(() => {
onChange(code)
})
},
Expand Down
3 changes: 3 additions & 0 deletions src/ui/NodeDecorators/FrontmatterEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type YamlConfig = Array<{ key: string; value: string }>

export const FrontmatterEditor = ({ yaml, onChange }: FrontmatterEditorProps) => {
const yamlConfig = React.useMemo<YamlConfig>(() => {
if (!yaml) {
return []
}
return Object.entries(YamlParser.load(yaml) as Record<string, string>).map(([key, value]) => ({ key, value }))
}, [yaml])

Expand Down
4 changes: 2 additions & 2 deletions src/ui/NodeDecorators/useCodeMirrorRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useCodeMirrorRef(nodeKey: string, editorType: 'codeblock' | 'san
const selectionEnd = state.selection.ranges[0].to

if (docLength === selectionEnd) {
activeEditor.update(() => {
activeEditor?.update(() => {
const node = $getNodeByKey(nodeKey)!
const nextSibling = node.getNextSibling()
if (nextSibling) {
Expand All @@ -40,7 +40,7 @@ export function useCodeMirrorRef(nodeKey: string, editorType: 'codeblock' | 'san
const selectionStart = state.selection.ranges[0].from

if (selectionStart === 0) {
activeEditor.update(() => {
activeEditor?.update(() => {
const node = $getNodeByKey(nodeKey)!
const previousSibling = node.getPreviousSibling()
if (previousSibling) {
Expand Down

0 comments on commit dc9d845

Please sign in to comment.