Skip to content
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

Add source.cpp contentName #47

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const languages = [
{ name: 'clojure', language: 'clojure', identifiers: ['clj', 'cljs', 'clojure'], source: 'source.clojure' },
{ name: 'coffee', language: 'coffee', identifiers: ['coffee', 'Cakefile', 'coffee.erb'], source: 'source.coffee' },
{ name: 'c', language: 'c', identifiers: ['c', 'h'], source: 'source.c' },
{ name: 'cpp', language: 'cpp', identifiers: ['cpp', 'c\\+\\+', 'cxx'], source: 'source.cpp' },
{ name: 'cpp', language: 'cpp', identifiers: ['cpp', 'c\\+\\+', 'cxx'], source: 'source.cpp', additionalContentName: ['source.cpp'] },
{ name: 'diff', language: 'diff', identifiers: ['patch', 'diff', 'rej'], source: 'source.diff' },
{ name: 'dockerfile', language: 'dockerfile', identifiers: ['dockerfile', 'Dockerfile'], source: 'source.dockerfile' },
{ name: 'git_commit', identifiers: ['COMMIT_EDITMSG', 'MERGE_MSG'], source: 'text.git-commit' },
Expand Down Expand Up @@ -62,7 +62,7 @@ const languages = [
{ name: 'markdown', language: 'markdown', identifiers: ['markdown', 'md'], source: 'text.html.markdown' },
];

const fencedCodeBlockDefinition = (name, identifiers, sourceScope, language) => {
const fencedCodeBlockDefinition = (name, identifiers, sourceScope, language, additionalContentName) => {
if (!Array.isArray(sourceScope)) {
sourceScope = [sourceScope];
}
Expand All @@ -72,6 +72,11 @@ const fencedCodeBlockDefinition = (name, identifiers, sourceScope, language) =>
const scopes = sourceScope.map(scope =>
`- { include: '${scope}' }`).join('\n');

let contentName = `meta.embedded.block.${language}`;
if (additionalContentName) {
contentName += ` ${additionalContentName.join(' ')}`;
}

return `fenced_code_block_${name}:
begin:
(^|\\G)(\\s*)(\`{3,}|~{3,})\\s*(?i:(${identifiers.join('|')})(\\s+[^\`~]*)?$)
Expand All @@ -88,7 +93,7 @@ const fencedCodeBlockDefinition = (name, identifiers, sourceScope, language) =>
patterns:
- begin: (^|\\G)(\\s*)(.*)
while: (^|\\G)(?!\\s*([\`~]{3,})\\s*$)
contentName: meta.embedded.block.${language}
contentName: ${contentName}
patterns:
${indent(4, scopes)}
`;
Expand All @@ -104,7 +109,7 @@ const fencedCodeBlockInclude = (name) =>

const fencedCodeBlockDefinitions = () =>
languages
.map(language => fencedCodeBlockDefinition(language.name, language.identifiers, language.source, language.language))
.map(language => fencedCodeBlockDefinition(language.name, language.identifiers, language.source, language.language, language.additionalContentName))
.join('\n');


Expand Down
2 changes: 1 addition & 1 deletion syntaxes/markdown.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@
<key>while</key>
<string>(^|\G)(?!\s*([`~]{3,})\s*$)</string>
<key>contentName</key>
<string>meta.embedded.block.cpp</string>
<string>meta.embedded.block.cpp source.cpp</string>
<key>patterns</key>
<array>
<dict>
Expand Down