Add table of contents to Help Debug Editor output
This commit is contained in:
parent
4d59f6dfdc
commit
9914fc35ab
|
@ -277,6 +277,12 @@ debug = () ->
|
||||||
# Get current editor
|
# Get current editor
|
||||||
editor = atom.workspace.getActiveTextEditor()
|
editor = atom.workspace.getActiveTextEditor()
|
||||||
|
|
||||||
|
linkifyTitle = (title) ->
|
||||||
|
title = title.toLowerCase()
|
||||||
|
p = title.split(/[\s,+#;,\/?:@&=+$]+/) # split into parts
|
||||||
|
sep = "-"
|
||||||
|
p.join(sep)
|
||||||
|
|
||||||
# Check if there is an active editor
|
# Check if there is an active editor
|
||||||
if not editor?
|
if not editor?
|
||||||
return confirm("Active Editor not found.\n" +
|
return confirm("Active Editor not found.\n" +
|
||||||
|
@ -284,13 +290,23 @@ debug = () ->
|
||||||
return unless confirm('Are you ready to debug Atom Beautify?\n\n' +
|
return unless confirm('Are you ready to debug Atom Beautify?\n\n' +
|
||||||
'Warning: This will change your current clipboard contents.')
|
'Warning: This will change your current clipboard contents.')
|
||||||
debugInfo = ""
|
debugInfo = ""
|
||||||
|
headers = []
|
||||||
|
tocEl = "<TABLEOFCONTENTS/>"
|
||||||
addInfo = (key, val) ->
|
addInfo = (key, val) ->
|
||||||
debugInfo += "**#{key}**: #{val}\n\n"
|
if key?
|
||||||
|
debugInfo += "**#{key}**: #{val}\n\n"
|
||||||
|
else
|
||||||
|
debugInfo += "#{val}\n\n"
|
||||||
addHeader = (level, title) ->
|
addHeader = (level, title) ->
|
||||||
debugInfo += "#{Array(level+1).join('#')} #{title}\n\n"
|
debugInfo += "#{Array(level+1).join('#')} #{title}\n\n"
|
||||||
|
headers.push({
|
||||||
|
level, title
|
||||||
|
})
|
||||||
addHeader(1, "Atom Beautify - Debugging information")
|
addHeader(1, "Atom Beautify - Debugging information")
|
||||||
debugInfo += "The following debugging information was " +
|
debugInfo += "The following debugging information was " +
|
||||||
"generated by `Atom Beautify` on `#{new Date()}`." +
|
"generated by `Atom Beautify` on `#{new Date()}`." +
|
||||||
|
"\n\n---\n\n" +
|
||||||
|
tocEl +
|
||||||
"\n\n---\n\n"
|
"\n\n---\n\n"
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
|
@ -340,11 +356,13 @@ debug = () ->
|
||||||
|
|
||||||
# Contents
|
# Contents
|
||||||
codeBlockSyntax = (language?.name ? grammarName).toLowerCase().split(' ')[0]
|
codeBlockSyntax = (language?.name ? grammarName).toLowerCase().split(' ')[0]
|
||||||
addInfo('Original File Contents', "\n```#{codeBlockSyntax}\n#{text}\n```")
|
addHeader(3, 'Original File Contents')
|
||||||
|
addInfo(null, "\n```#{codeBlockSyntax}\n#{text}\n```")
|
||||||
|
|
||||||
addInfo('Package Settings', "\n" +
|
addHeader(3, 'Package Settings')
|
||||||
"The raw package settings options\n" +
|
addInfo(null,
|
||||||
"```json\n#{JSON.stringify(atom.config.get('atom-beautify'), undefined, 4)}\n```")
|
"The raw package settings options\n" +
|
||||||
|
"```json\n#{JSON.stringify(atom.config.get('atom-beautify'), undefined, 4)}\n```")
|
||||||
|
|
||||||
# Beautification Options
|
# Beautification Options
|
||||||
addHeader(2, "Beautification options")
|
addHeader(2, "Beautification options")
|
||||||
|
@ -391,9 +409,9 @@ debug = () ->
|
||||||
"```json\n#{JSON.stringify(preTransformedOptions, undefined, 4)}\n```")
|
"```json\n#{JSON.stringify(preTransformedOptions, undefined, 4)}\n```")
|
||||||
if selectedBeautifier
|
if selectedBeautifier
|
||||||
addHeader(3, 'Final Options')
|
addHeader(3, 'Final Options')
|
||||||
addInfo('Final Options', "\n" +
|
addInfo(null,
|
||||||
"Final combined and transformed options that are used\n" +
|
"Final combined and transformed options that are used\n" +
|
||||||
"```json\n#{JSON.stringify(finalOptions, undefined, 4)}\n```")
|
"```json\n#{JSON.stringify(finalOptions, undefined, 4)}\n```")
|
||||||
|
|
||||||
#
|
#
|
||||||
logs = ""
|
logs = ""
|
||||||
|
@ -421,7 +439,23 @@ debug = () ->
|
||||||
result, "original", "beautified")
|
result, "original", "beautified")
|
||||||
addInfo('Original vs. Beautified Diff', "\n```#{codeBlockSyntax}\n#{diff}\n```")
|
addInfo('Original vs. Beautified Diff', "\n```#{codeBlockSyntax}\n#{diff}\n```")
|
||||||
|
|
||||||
addInfo('Logs', "\n```\n#{logs}\n```")
|
addHeader(3, "Logs")
|
||||||
|
addInfo(null, "```\n#{logs}\n```")
|
||||||
|
|
||||||
|
# Build Table of Contents
|
||||||
|
toc = "## Table Of Contents\n"
|
||||||
|
for header in headers
|
||||||
|
###
|
||||||
|
- Heading 1
|
||||||
|
- Heading 1.1
|
||||||
|
###
|
||||||
|
indent = " " # 2 spaces
|
||||||
|
bullet = "-"
|
||||||
|
indentNum = header.level - 2
|
||||||
|
if indentNum >= 0
|
||||||
|
toc += ("#{Array(indentNum+1).join(indent)}#{bullet} [#{header.title}](\##{linkifyTitle(header.title)})\n")
|
||||||
|
# Replace TABLEOFCONTENTS
|
||||||
|
debugInfo = debugInfo.replace(tocEl, toc)
|
||||||
|
|
||||||
# Save to clipboard
|
# Save to clipboard
|
||||||
atom.clipboard.write(debugInfo)
|
atom.clipboard.write(debugInfo)
|
||||||
|
|
Loading…
Reference in New Issue