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

Commit

Permalink
refactor: naming conventions and styling
Browse files Browse the repository at this point in the history
- `htmlentities` become `character-reference`
- `reference` become `xref`
- ordering `explicit` after `code-block`
- `code-block`  respect conventions
-  better code blocks patterns
  • Loading branch information
ldez committed May 13, 2016
1 parent 8ae2de7 commit dc2162e
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 203 deletions.
266 changes: 170 additions & 96 deletions grammars/language-asciidoc.cson

Large diffs are not rendered by default.

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 @@ -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'
]
50 changes: 38 additions & 12 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,59 @@ 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'
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'
]

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

# 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 @@ -86,11 +111,12 @@ module.exports =
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
57 changes: 43 additions & 14 deletions spec/code-block-generator-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,62 @@ describe 'Code block generator', ->
it 'should generate default code block', ->
languages = []
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 2 # Number of blocks
expect(codeBlocks).toHaveLength 3 # 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'
]

it 'should generate default code block with attributes only', ->
languages = []
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 3 # Number of blocks
expect(codeBlocks[1]).toEqualJson
begin: '^\\[([^\\]]+)\\]$'
beginCaptures:
0: name: 'support.asciidoc'
1: name: 'markup.meta.attribute-list.asciidocc'
end: '(?<=----)[\\r\\n]+$'
patterns: [
name: 'markup.raw.asciidoc'
begin: '^(-{4,})\\s*$'
beginCaptures:
0: name: 'support.asciidoc'
patterns: [
include: '#block-callout'
]
end: '^\\1*$'
endCaptures:
0: name: 'support.asciidoc'
]

it 'should generate listing block', ->
languages = []
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 2 # Number of blocks
expect(codeBlocks[1]).toEqualJson
expect(codeBlocks).toHaveLength 3 # Number of blocks
expect(codeBlocks[2]).toEqualJson
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'
Expand All @@ -45,14 +72,15 @@ describe 'Code block generator', ->
pattern: 'javascript|js', type: 'source', code: 'js'
]
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 3 # Number of blocks
expect(codeBlocks).toHaveLength 4 # Number of blocks
expect(codeBlocks[0]).toEqualJson
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 All @@ -78,14 +106,15 @@ describe 'Code block generator', ->
pattern: 'c(pp|\\+\\+)', type: 'source', code: 'cpp'
]
codeBlocks = generator.makeAsciidocBlocks(languages)
expect(codeBlocks).toHaveLength 3 # Number of blocks
expect(codeBlocks).toHaveLength 4 # Number of blocks
expect(codeBlocks[0]).toEqualJson
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

0 comments on commit dc2162e

Please sign in to comment.