Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Open
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
28 changes: 11 additions & 17 deletions lib/rocco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,9 @@ def detect_language
include CommentStyles

def generate_comment_chars
comment_hash = { :single => @options[:comment_chars], :multi => nil, :heredoc => nil }
@_commentchar ||=
if COMMENT_STYLES[@options[:language]]
COMMENT_STYLES[@options[:language]]
else
{ :single => @options[:comment_chars], :multi => nil, :heredoc => nil }
end
COMMENT_STYLES[@options[:language]] or comment_hash
end

# Internal Parsing and Highlighting
Expand Down Expand Up @@ -331,12 +328,9 @@ def parse(data)
# `def func():\n print "omg!"`
def normalize_leading_spaces(sections)
sections.map do |section|
if section.any? && section[0].any?
leading_space = section[0][0].match("^\s+")
if leading_space
section[0] =
section[0].map{ |line| line.sub(/^#{leading_space.to_s}/, '') }
end
if section.any? && section.first.any?
leading_space = section.first.first.match("^\s+")
section[0] = section.first.map{ |l| l.sub(/^#{leading_space}/, '') } if leading_space
end
section
end
Expand All @@ -349,9 +343,9 @@ def split(sections)
docs_blocks, code_blocks = [], []
sections.each do |docs,code|
docs_blocks << docs.join("\n")
code_blocks << code.map do |line|
tabs = line.match(/^(\t+)/)
tabs ? line.sub(/^\t+/, ' ' * tabs.captures[0].length) : line
code_blocks << code.map do |l|
tabs = l.match /^(\t+)/
if tabs then l.sub(/^\t+/, ' ' * tabs.captures[0].length) else l end
end.join("\n")
end
[docs_blocks, code_blocks]
Expand All @@ -361,9 +355,9 @@ def split(sections)
# Markdown syntax.
def docblock(docs)
docs.map do |doc|
doc.split("\n").map do |line|
line.match(/^@\w+/) ? line.sub(/^@(\w+)\s+/, '> **\1** ')+" " : line
end.join("\n")
doc.split("\n").map do |l|
if l.match(/^@\w+/) then l.sub(/^@(\w+)\s+/, '> **\1** ') + " " else l end
end.join "\n"
end
end

Expand Down