Skip to content

Commit

Permalink
Fix content editor state being changed due to trailing newlne
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Aug 25, 2024
1 parent 533403f commit 68fb955
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/services/contents/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ const getFrontmatterDelimiters = (format, delimiter) => {
* @returns {FrontMatterFormat} JSON, TOML or YAML front matter.
*/
const detectFrontMatterFormat = (text) => {
const str = text.trim();

if (str.startsWith('{')) {
if (text.startsWith('{')) {
return 'json-frontmatter';
}

if (str.startsWith('+++')) {
if (text.startsWith('+++')) {
return 'toml-frontmatter';
}

Expand All @@ -99,6 +97,8 @@ const parseEntryFile = ({
parserConfig: { extension, format, frontmatterDelimiter },
},
}) => {
text = text.trim();

format ||= /** @type {FileFormat | undefined} */ (
['md', 'markdown'].includes(extension ?? '') || path.match(/\.(?:md|markdown)$/)
? detectFrontMatterFormat(text)
Expand Down

0 comments on commit 68fb955

Please sign in to comment.