Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

refactor: naming conventions and styling #121

Merged
merged 3 commits into from
May 15, 2016
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
601 changes: 325 additions & 276 deletions grammars/language-asciidoc.cson

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions grammars/repositories/blocks/quote-grammar.cson
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ patterns: [
name: 'markup.italic.quotes.attributes.asciidoc'
begin: '^\\[(quote|verse)(, ([\\w ]+))?(, ([\\w ]+))?'
beginCaptures:
1: name: 'none.quotes.label.asciidoc'
3: name: 'none.quotes.attribution.asciidoc'
5: name: 'none.quotes.citetitle.asciidoc'
1: name: 'entity.name.function.label.asciidoc'
3: name: 'string.unquoted.attribution.asciidoc'
5: name: 'string.unquoted.citetitle.asciidoc'
end: '\\]$'
,
# Matches quote block
Expand Down
8 changes: 4 additions & 4 deletions grammars/repositories/inlines/characters-grammar.cson
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ key: 'characters'

patterns: [

# Matches characters
# Matches characters references.
#
# Examples
#
# Dungeons & Dragons
#
name: 'markup.htmlentity.asciidoc'
name: 'markup.character-reference.asciidoc'
match: '(?<!\\\\)(\&)(\\S+?)(;)'
captures:
1: name: 'support.constant.asciidoc'
3: name: 'support.constant.asciidoc'
1: name: 'constant.character.asciidoc'
3: name: 'constant.character.asciidoc'
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ patterns: [
captures:
1: name: 'entity.name.function.asciidoc'
2: name: 'markup.link.asciidoc'
3: name: 'string.unquoted.asciidoc'
3:
name: 'string.unquoted.asciidoc'
patterns: [
include: '#attribute-reference'
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ patterns: [
# This is a normal paragraph.
#
name: 'markup.explicit.asciidoc'
match: '^\\[((normal|literal|listing|TIP|NOTE|IMPORTANT|WARNING|CAUTION|partintro|comment|example|sidebar|source|music|latex|graphviz))\\]$'
match: '^\\[((normal|literal|listing|TIP|NOTE|IMPORTANT|WARNING|CAUTION|partintro|comment|example|sidebar|source|music|latex|graphviz))\\]$(?<!\\n---)'
captures:
1: name: 'support.constant.asciidoc'
1: name: 'entity.name.function.asciidoc'
]
38 changes: 22 additions & 16 deletions lib/code-block-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ module.exports =
begin: "^\\[(source),\\p{Blank}*(?i:(#{lang.pattern}))(?:,([^\]]*))?\\]$"
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'constant.asciidoc'
2: name: 'string.asciidoc'
1: name: 'entity.name.function.asciidoc'
2: name: 'entity.name.type.asciidoc'
3:
name: 'markup.meta.attribute-list.asciidoc'
patterns: [
include: '#attribute-reference'
]
Expand All @@ -32,35 +33,39 @@ module.exports =

# add generic block
codeBlocks.push
begin: '^\\[(source)(?:,([^,\\]]*)){0,2}\\]$'
begin: '^\\[(source)(,([^\\]]*))?\\]$'
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'constant.asciidoc'
2: name: 'string.asciidoc'
end: '(?<=----)[\\r\\n]+$'
1: name: 'entity.name.function.asciidoc'
2: name: 'markup.meta.attribute-list.asciidoc'
patterns: [
name: 'markup.raw.asciidoc'
begin: '^(-{4,})\\s*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [include: '#block-callout']
patterns: [
include: '#block-callout'
]
end: '^\\1*$'
endCaptures:
0: name: 'support.asciidoc'
]
end: '(?<=----)[\\r\\n]+$'

# add listing block
codeBlocks.push
name: 'markup.raw.asciidoc'
begin: '^(-{4,})\\s*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [include: '#block-callout']
patterns: [
include: '#block-callout'
]
end: '^\\1*$'
endCaptures:
0: name: 'support.asciidoc'

if debug
console.log CSON.stringify codeBlocks
if debug then console.log CSON.stringify codeBlocks
codeBlocks

makeMarkdownBlocks: (languages, debug = false) ->
Expand All @@ -70,27 +75,28 @@ module.exports =
begin: "^\\s*(`{3,})\\s*(?i:(#{lang.pattern}))\\s*$"
beginCaptures:
0: name: 'support.asciidoc'
end: '^\\s*\\1\\s*$'
endCaptures:
0: name: 'support.asciidoc'
contentName: "#{lang.type}.embedded.#{lang.code}"
patterns: [
include: '#block-callout'
,
include: "#{lang.type}.#{lang.code}"
]
end: '^\\s*\\1\\s*$'
endCaptures:
0: name: 'support.asciidoc'

# add generic block
codeBlocks.push
name: 'markup.raw.asciidoc'
begin: '^\\s*(`{3,}).*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [include: '#block-callout']
patterns: [
include: '#block-callout'
]
end: '^\\s*\\1\\s*$'
endCaptures:
0: name: 'support.asciidoc'

if debug
console.log CSON.stringify codeBlocks
if debug then console.log CSON.stringify codeBlocks
codeBlocks
14 changes: 7 additions & 7 deletions spec/blocks/code-block-grammar-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe 'Should tokenizes code block when', ->
expect(tokens).toHaveLength 7 # Number of lines
expect(tokens[0]).toHaveLength 5
expect(tokens[0][0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'constant.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.function.asciidoc']
expect(tokens[0][2]).toEqualJson value: ',', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'shell', scopes: ['source.asciidoc', 'support.asciidoc', 'string.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'shell', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.type.asciidoc']
expect(tokens[0][4]).toEqualJson value: ']', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[1]).toHaveLength 1
expect(tokens[1][0]).toEqualJson value: '----', scopes: ['source.asciidoc', 'markup.code.shell.asciidoc', 'support.asciidoc']
Expand Down Expand Up @@ -77,13 +77,13 @@ describe 'Should tokenizes code block when', ->
expect(tokens).toHaveLength 4 # Number of lines
expect(tokens[0]).toHaveLength 9
expect(tokens[0][0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'constant.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.function.asciidoc']
expect(tokens[0][2]).toEqualJson value: ',', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'java', scopes: ['source.asciidoc', 'support.asciidoc', 'string.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'java', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.type.asciidoc']
expect(tokens[0][4]).toEqualJson value: ',', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][5]).toEqualJson value: 'subs="', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][6]).toEqualJson value: '{markup-in-source}', scopes: ['source.asciidoc', 'support.asciidoc', 'markup.substitution.attribute-reference.asciidoc']
expect(tokens[0][7]).toEqualJson value: '"', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][5]).toEqualJson value: 'subs="', scopes: ['source.asciidoc', 'support.asciidoc', 'markup.meta.attribute-list.asciidoc']
expect(tokens[0][6]).toEqualJson value: '{markup-in-source}', scopes: ['source.asciidoc', 'support.asciidoc', 'markup.meta.attribute-list.asciidoc', 'markup.substitution.attribute-reference.asciidoc']
expect(tokens[0][7]).toEqualJson value: '"', scopes: ['source.asciidoc', 'support.asciidoc', 'markup.meta.attribute-list.asciidoc']
expect(tokens[0][8]).toEqualJson value: ']', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[1]).toHaveLength 1
expect(tokens[1][0]).toEqualJson value: '----', scopes: ['source.asciidoc', 'markup.code.java.asciidoc', 'support.asciidoc']
Expand Down
16 changes: 8 additions & 8 deletions spec/blocks/quote-grammar-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe 'Should tokenizes quote block when', ->
expect(tokens).toHaveLength 4
expect(tokens[0]).toHaveLength 7
expect(tokens[0][0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'quote', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.label.asciidoc' ]
expect(tokens[0][1]).toEqualJson value: 'quote', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'entity.name.function.label.asciidoc' ]
expect(tokens[0][2]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'Erwin Schrödinger', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.attribution.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'Erwin Schrödinger', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'string.unquoted.attribution.asciidoc']
expect(tokens[0][4]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[0][5]).toEqualJson value: 'Sorry', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.citetitle.asciidoc']
expect(tokens[0][5]).toEqualJson value: 'Sorry', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'string.unquoted.citetitle.asciidoc']
expect(tokens[0][6]).toEqualJson value: ']', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[1]).toHaveLength 1
expect(tokens[1][0]).toEqualJson value: '____', scopes: ['source.asciidoc', 'markup.italic.quotes.asciidoc']
Expand All @@ -43,21 +43,21 @@ describe 'Should tokenizes quote block when', ->
{tokens} = grammar.tokenizeLine '[verse, Homer Simpson]\n'
expect(tokens).toHaveLength 6
expect(tokens[0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[1]).toEqualJson value: 'verse', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.label.asciidoc']
expect(tokens[1]).toEqualJson value: 'verse', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'entity.name.function.label.asciidoc']
expect(tokens[2]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[3]).toEqualJson value: 'Homer Simpson', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.attribution.asciidoc']
expect(tokens[3]).toEqualJson value: 'Homer Simpson', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'string.unquoted.attribution.asciidoc']
expect(tokens[4]).toEqualJson value: ']', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[5]).toEqualJson value: '\n', scopes: ['source.asciidoc']

it 'quote declarations with attribution and citation', ->
{tokens} = grammar.tokenizeLine '[quote, Erwin Schrödinger, Sorry]\n'
expect(tokens).toHaveLength 8
expect(tokens[0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[1]).toEqualJson value: 'quote', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.label.asciidoc']
expect(tokens[1]).toEqualJson value: 'quote', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'entity.name.function.label.asciidoc']
expect(tokens[2]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[3]).toEqualJson value: 'Erwin Schrödinger', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.attribution.asciidoc']
expect(tokens[3]).toEqualJson value: 'Erwin Schrödinger', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'string.unquoted.attribution.asciidoc']
expect(tokens[4]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[5]).toEqualJson value: 'Sorry', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'none.quotes.citetitle.asciidoc']
expect(tokens[5]).toEqualJson value: 'Sorry', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc', 'string.unquoted.citetitle.asciidoc']
expect(tokens[6]).toEqualJson value: ']', scopes: ['source.asciidoc', 'markup.italic.quotes.attributes.asciidoc']
expect(tokens[7]).toEqualJson value: '\n', scopes: ['source.asciidoc']

Expand Down
26 changes: 16 additions & 10 deletions spec/code-block-generator-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ describe 'Code block generator', ->
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 2 # Number of blocks
expect(codeBlocks[0]).toEqualJson
begin: '^\\[(source)(?:,([^,\\]]*)){0,2}\\]$'
begin: '^\\[(source)(,([^\\]]*))?\\]$'
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'constant.asciidoc'
2: name: 'string.asciidoc'
1: name: 'entity.name.function.asciidoc'
2: name: 'markup.meta.attribute-list.asciidoc'
end: '(?<=----)[\\r\\n]+$'
patterns: [
name: 'markup.raw.asciidoc'
begin: '^(-{4,})\\s*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [include: '#block-callout']
patterns: [
include: '#block-callout'
]
end: '^\\1*$'
endCaptures:
0: name: 'support.asciidoc'
]
end: '(?<=----)[\\r\\n]+$'

it 'should generate listing block', ->
languages = []
Expand All @@ -35,7 +37,9 @@ describe 'Code block generator', ->
begin: '^(-{4,})\\s*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [include: '#block-callout']
patterns: [
include: '#block-callout'
]
end: '^\\1*$'
endCaptures:
0: name: 'support.asciidoc'
Expand All @@ -50,9 +54,10 @@ describe 'Code block generator', ->
begin: '^\\[(source),\\p{Blank}*(?i:(javascript|js))(?:,([^\]]*))?\\]$'
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'constant.asciidoc'
2: name: 'string.asciidoc'
1: name: 'entity.name.function.asciidoc'
2: name: 'entity.name.type.asciidoc'
3:
name: 'markup.meta.attribute-list.asciidoc'
patterns: [
include: '#attribute-reference'
]
Expand Down Expand Up @@ -83,9 +88,10 @@ describe 'Code block generator', ->
begin: '^\\[(source),\\p{Blank}*(?i:(c(pp|\\+\\+)))(?:,([^\]]*))?\\]$'
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'constant.asciidoc'
2: name: 'string.asciidoc'
1: name: 'entity.name.function.asciidoc'
2: name: 'entity.name.type.asciidoc'
3:
name: 'markup.meta.attribute-list.asciidoc'
patterns: [
include: '#attribute-reference'
]
Expand Down
6 changes: 3 additions & 3 deletions spec/inlines/characters-grammar-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe 'Should tokenizes characters when', ->
{tokens} = grammar.tokenizeLine 'Dungeons &amp; Dragons'
expect(tokens).toHaveLength 5
expect(tokens[0]).toEqualJson value: 'Dungeons ', scopes: ['source.asciidoc']
expect(tokens[1]).toEqualJson value: '&', scopes: ['source.asciidoc', 'markup.htmlentity.asciidoc', 'support.constant.asciidoc']
expect(tokens[2]).toEqualJson value: 'amp', scopes: ['source.asciidoc', 'markup.htmlentity.asciidoc']
expect(tokens[3]).toEqualJson value: ';', scopes: ['source.asciidoc', 'markup.htmlentity.asciidoc', 'support.constant.asciidoc']
expect(tokens[1]).toEqualJson value: '&', scopes: ['source.asciidoc', 'markup.character-reference.asciidoc', 'constant.character.asciidoc']
expect(tokens[2]).toEqualJson value: 'amp', scopes: ['source.asciidoc', 'markup.character-reference.asciidoc']
expect(tokens[3]).toEqualJson value: ';', scopes: ['source.asciidoc', 'markup.character-reference.asciidoc', 'constant.character.asciidoc']
expect(tokens[4]).toEqualJson value: ' Dragons', scopes: ['source.asciidoc']

it 'contains space (invalid context)', ->
Expand Down
4 changes: 2 additions & 2 deletions spec/partials/block-callout-grammar-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe 'Should tokenizes callout in code block when', ->
expect(tokens).toHaveLength 8
expect(tokens[0]).toHaveLength 5
expect(tokens[0][0]).toEqualJson value: '[', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'constant.asciidoc']
expect(tokens[0][1]).toEqualJson value: 'source', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.function.asciidoc']
expect(tokens[0][2]).toEqualJson value: ', ', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'js', scopes: ['source.asciidoc', 'support.asciidoc', 'string.asciidoc']
expect(tokens[0][3]).toEqualJson value: 'js', scopes: ['source.asciidoc', 'support.asciidoc', 'entity.name.type.asciidoc']
expect(tokens[0][4]).toEqualJson value: ']', scopes: ['source.asciidoc', 'support.asciidoc']
expect(tokens[1]).toHaveLength 1
expect(tokens[1][0]).toEqualJson value: '----', scopes: ['source.asciidoc', 'markup.code.js.asciidoc', 'support.asciidoc']
Expand Down
Loading