mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 01:13:08 +02:00
#230 - front matter json support added
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
- Added default field value for content type fields
|
||||
- HMR support for panel webview development
|
||||
- [#198](https://github.com/estruyf/vscode-front-matter/issues/198): Additional media sort options (alt, caption, and size).
|
||||
- [#230](https://github.com/estruyf/vscode-front-matter/issues/230): JSON front matter support added.
|
||||
|
||||
## [5.10.0] - 2022-01-10
|
||||
|
||||
|
||||
+4
-2
@@ -830,12 +830,14 @@
|
||||
"default": "YAML",
|
||||
"enum": [
|
||||
"YAML",
|
||||
"TOML"
|
||||
"TOML",
|
||||
"JSON"
|
||||
],
|
||||
"markdownDescription": "Specify the type of Front Matter to use. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.taxonomy.frontmattertype)",
|
||||
"enumDescriptions": [
|
||||
"Specifies you want to use YAML markup for the front matter (default)",
|
||||
"Specifies you want to use TOML markup for the front matter"
|
||||
"Specifies you want to use TOML markup for the front matter",
|
||||
"Specifies you want to use JSON markup for the front matter"
|
||||
],
|
||||
"scope": "Taxonomy"
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as fs from "fs";
|
||||
import { DefaultFields, SETTINGS_CONTENT_DEFAULT_FILETYPE, SETTINGS_CONTENT_PLACEHOLDERS, SETTING_COMMA_SEPARATED_FIELDS, SETTING_DATE_FIELD, SETTING_DATE_FORMAT, SETTING_INDENT_ARRAY, SETTING_REMOVE_QUOTES, SETTING_TAXONOMY_CONTENT_TYPES, SETTING_TEMPLATES_PREFIX } from '../constants';
|
||||
import { DumpOptions } from 'js-yaml';
|
||||
import { TomlEngine, getFmLanguage, getFormatOpts } from './TomlEngine';
|
||||
import { Extension, Settings } from '.';
|
||||
import { Extension, Logger, Settings } from '.';
|
||||
import { format, parse } from 'date-fns';
|
||||
import { Notifications } from './Notifications';
|
||||
import { Article } from '../commands';
|
||||
@@ -388,6 +388,8 @@ export class ArticleHelper {
|
||||
await EditorHelper.showFile(fileName)
|
||||
}
|
||||
}];
|
||||
|
||||
Logger.error(error.message);
|
||||
|
||||
const editor = window.activeTextEditor;
|
||||
if (editor?.document.uri) {
|
||||
@@ -401,7 +403,6 @@ export class ArticleHelper {
|
||||
fmRange = MarkdownFoldingProvider.getFrontMatterRange(editor.document);
|
||||
}
|
||||
|
||||
|
||||
if (fmRange) {
|
||||
Extension.getInstance().diagnosticCollection.set(editor.document.uri, [{
|
||||
severity: DiagnosticSeverity.Error,
|
||||
|
||||
@@ -11,7 +11,7 @@ export const getFormatOpts = (format: string): { language: string, delimiters: s
|
||||
const formats: { [prop: string]: { language: string, delimiters: string | [string, string] | undefined }} = {
|
||||
yaml: { language: 'yaml', delimiters: '---' },
|
||||
toml: { language: 'toml', delimiters: '+++' },
|
||||
json: { language: 'json', delimiters: ['{', '}'] },
|
||||
json: { language: 'json', delimiters: '---' },
|
||||
};
|
||||
|
||||
return formats[format];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TextEditorDecorationType } from 'vscode';
|
||||
import { CancellationToken, FoldingContext, FoldingRange, FoldingRangeKind, FoldingRangeProvider, Range, TextDocument, window, Position } from 'vscode';
|
||||
import { SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT } from '../constants';
|
||||
import { SETTINGS_CONTENT_FRONTMATTER_HIGHLIGHT, SETTING_FRONTMATTER_TYPE } from '../constants';
|
||||
import { Settings } from '../helpers';
|
||||
import { FrontMatterDecorationProvider } from './FrontMatterDecorationProvider';
|
||||
|
||||
@@ -50,6 +50,15 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
|
||||
* @returns
|
||||
*/
|
||||
public static getFrontMatterRange(document?: TextDocument) {
|
||||
const language = Settings.get(SETTING_FRONTMATTER_TYPE) as string || "YAML";
|
||||
|
||||
let lineStart = "---";
|
||||
let lineEnd = "---";
|
||||
if (language === "TOML") {
|
||||
lineStart = "+++";
|
||||
lineEnd = lineStart;
|
||||
}
|
||||
|
||||
if (document) {
|
||||
const lines = document.getText().split('\n');
|
||||
|
||||
@@ -59,7 +68,7 @@ export class MarkdownFoldingProvider implements FoldingRangeProvider {
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (line.startsWith('---')) {
|
||||
if (line.startsWith(lineStart) || line.startsWith(lineEnd)) {
|
||||
if (i === 0 && start === null) {
|
||||
start = i;
|
||||
} else if (start !== null && end === null) {
|
||||
|
||||
Reference in New Issue
Block a user