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

Fix and enhance code segmentation for folded and embedded block-comments #120

Merged
merged 12 commits into from
Sep 18, 2013
Merged
62 changes: 49 additions & 13 deletions lib/languages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = LANGUAGES =
CSharp:
nameMatchers: ['.cs']
pygmentsLexer: 'csharp'
singleLineComment: ['//']
multiLineComment: ['/*', '*', '*/']
singleLineComment: ['//']
ignorePrefix: '}'
foldPrefix: '^'

Expand All @@ -37,19 +37,52 @@ module.exports = LANGUAGES =
CoffeeScript:
nameMatchers: ['.coffee', 'Cakefile']
pygmentsLexer: 'coffee-script'
# **CoffeScript's multi-line block-comment styles.**

# - Variant 1:
# (Variant 3 is preferred over this syntax, as soon as the pull-request
# mentioned below has been merged into coffee-script's codebase.)
###* }
* Tip: use '-' or '+' for bullet-lists instead of '*' to distinguish
* bullet-lists visually from this kind of block comments. The preceding
* whitespaces in the line-matcher and end-matcher are required. Without
* them this syntax makes no sense, as it is meant to produce comments
* like the following in compiled javascript:
*
* /**
* * A sample comment, having a preceding whitespace per line. Useful
* * to embed `@doctags` in javascript compiled from coffeescript.
* * <= COMBINE THESE TWO CHARS => /
*
* (The the final comment-mark above has been TWEAKED to not raise an error)
###
# - Variant 2:
### }
Uses the the below defined syntax, without preceding `#` per line. This is
the syntax for what the definition is actually meant for !
###
# - Variant 3:
# (This syntax produces arkward comments in the compiled javascript, if
# the pull-request _“[Format block-comments
# better](<https://github.com/jashkenas/coffee-script/pull/3132)”_ has
# not been applied to coffee-script's codebase …)
### }
# The block-comment line-matcher `'#'` also works on lines not starting
# with `'#'`, because we add unmatched lines to the comments once we are
# in a multi-line comment-block and until we left them …
###
multiLineComment : [
# This kind of comment is not yet enabled here, but works, if foldPrefix
# has been set to something else than '-'. Then we can use '-' for
# bullet-lists instead of '*' to distinguish bullet-lists from this kind
# of block comments. A patch to switch from '-' to '~' has been prepared
# and waits for merging.
# } '###*', ' *', '###',

# The block-comment line-matcher `'#'` also works on lines not starting
# with `'#'`, because we add unmatched lines to the comments once we are
# in a multi-line comment-block and until we left them …
'###', '#', '###'
# Syntax definition for variant 1.
'###*', ' *', ' ###',
# Syntax definition for variant 2 and 3.
'###' , '#' , '###'
]
# This flag indicates if the end-mark of block-comments (the third value in
# the list of 3-tuples above) must correspond to the initial block-mark (the
# first value in the list of 3-tuples above). If this flag is missing it
# defaults to `true`. If true it allows one to nest block-comments in
# different syntax-definitions, like in handlebars or html+php.
strictMultiLineEnd:false
singleLineComment: ['#']
ignorePrefix: '}'
foldPrefix: '^'
Expand All @@ -68,6 +101,9 @@ module.exports = LANGUAGES =
'<!--', '', '-->', # HTML block comments go first, for code highlighting / segment splitting purposes
'{{!', '', '}}' # Actual handlebars block comments
]
# See above for a description of this flag.
strictMultiLineEnd:true
# This one differs from the common `ignorePrefix` of all other languages !
ignorePrefix: '#'
foldPrefix: '^'

Expand Down Expand Up @@ -95,8 +131,8 @@ module.exports = LANGUAGES =
JavaScript:
nameMatchers: ['.js']
pygmentsLexer: 'javascript'
singleLineComment: ['//']
multiLineComment: ['/*', '*', '*/']
singleLineComment: ['//']
ignorePrefix: '}'
foldPrefix: '^'

Expand Down
12 changes: 7 additions & 5 deletions lib/styles/default/behavior.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ $ ->
else
search$.val ''

# Make folded code blocks toggleable
$('.code.folded .marker').each (index, marker) ->
marker$ = $(marker)
marker$.click (evt) ->
marker$.parent().toggleClass 'folded'
# Make folded code blocks toggleable; the marker and the code are clickable.
$('.code.folded').each (index, code) ->
code$ = $(code)
code$.click (evt) ->
code$.toggleClass 'folded'
evt.preventDefault()
return false
2 changes: 1 addition & 1 deletion lib/styles/default/docPage.jade
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ html(lang="en")
- if (segments[i].highlightedCode != '')
- if (segments[i].foldMarker != '')
.code.folded
.marker.wrapper
.wrapper.marker
span.c1!= segments[i].foldMarker
.wrapper!= segments[i].highlightedCode
- else
Expand Down
2 changes: 1 addition & 1 deletion lib/styles/default/style.css

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/styles/default/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,22 @@ input[type="search"]

// ## Code folding

.code .marker, .code .marker.wrapper, .code .wrapper.marker
display: none

.code.folded
.wrapper
display: none
cursor: default

.marker
+border-radius(0.2em)
+box-shadow(#2f3539 1px 1px 1px 0)
display: block
display: inline-block
border: 1px solid #73787f
padding: 0.2em 0.5em
margin-left: -0.5em
margin-right: -0.5em
background: #58616b
font: 12px 'Droid Sans Mono', Menlo, Monaco, monospace
text-shadow: #2f3539 1px 1px 0px
Expand Down
Loading