Skip to content

Commit ffecfbf

Browse files
committed
fix: beautify only code-samples
1 parent dcd34e5 commit ffecfbf

File tree

4 files changed

+33
-43
lines changed

4 files changed

+33
-43
lines changed

index.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ class Styledown {
6767

6868
html = $.html()
6969
}
70-
return this.prettyprint(html, { wrap_line_length: 0, ...config })
70+
html = html.trim()
71+
72+
// cheerio output tends to have a bunch of extra newlines. kill them.
73+
html = html.replace(/\n\n+/g, "\n\n")
74+
75+
return html
7176
}
7277

7378
/**
@@ -139,11 +144,12 @@ class Styledown {
139144
process(raws, options) {
140145
return raws.map((raw) => {
141146
let $ = Cheerio.load(raw.html)
147+
let config = processConfig(raw.src, options)
148+
removeConfig($)
149+
142150
let highlightHTML = this.highlightHTML.bind(this)
143151
let p = this.prefix.bind(this)
144152

145-
let config = processConfig(raw.src, options)
146-
removeConfig($)
147153

148154
// let pre = this.options.prefix
149155

@@ -165,33 +171,32 @@ class Styledown {
165171
})
166172
}
167173

168-
/**
169-
* prettyprint() : doc.prettyprint(html)
170-
* (private) Reindents given `html` based on the indent size option.
171-
*
172-
* doc.prettyprint('<div><a>hello</a></div>')
173-
* => "<div>\n <a>hello</a>\n</div>"
174-
*/
175-
176-
prettyprint(html, options) {
174+
// no use at the moment
175+
// /**
176+
// * prettyprint() : doc.prettyprint(html)
177+
// * (private) Reindents given `html` based on the indent size option.
178+
// *
179+
// * doc.prettyprint('<div><a>hello</a></div>')
180+
// * => "<div>\n <a>hello</a>\n</div>"
181+
// */
177182

178-
let output = html.trim()
183+
// prettyprint() {
184+
// let html = this.toHTML()
179185

180-
output = beautifyHTML(html, options)
186+
// let config = this.raws.reduce((finalConfig, raw) => {
187+
// return extend(finalConfig, raw.config)
188+
// }, this.options)
181189

182-
// cheerio output tends to have a bunch of extra newlines. kill them.
183-
output = output.replace(/\n\n+/g, "\n\n")
184-
185-
return output
186-
}
190+
// return beautifyHTML(html, { config })
191+
// }
187192

188193
/**
189194
* highlightHTML():
190195
* (private) Syntax highlighting helper
191196
*/
192197

193198
highlightHTML(html) {
194-
html = this.prettyprint(html)
199+
html = beautifyHTML(html)
195200
return hljs.highlight('html', html).value
196201
}
197202

@@ -248,6 +253,7 @@ Styledown.parse = function (source, options) {
248253
return new Styledown(source, options).toHTML()
249254
}
250255

256+
251257
/**
252258
* Styledown.version:
253259
* The version number in semver format.

lib/utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ function htmlize(src, filePath = '.') {
8787
if (src.substr(0, 1) === '<') {
8888
return src
8989
} else {
90-
let html = Pug.render(src, {
90+
return Pug.render(src, {
9191
filename: filePath,
9292
doctype: 'html'
9393
})
94-
return beautifyHTML(html)
9594
}
9695
}
9796

test/markdown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Markdown', function() {
2323
expect(this.$).have.selector('p.sg')
2424
})
2525
it('html template', function() {
26-
expect(this.html).match(/!DOCTYPE html/)
26+
expect(this.html).match(/!doctype html/)
2727
expect(this.html).match(/body/)
2828
expect(this.html).match(/head/)
2929
expect(this.$).have.selector('meta[charset="utf-8"]')

test/pretty_print.js

+5-20
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,17 @@ describe('Pretty Print', function() {
1111
})
1212
})
1313

14-
it('indent <head>', function() {
15-
expect(this.html).match(/\n {2}<head/)
14+
it('no indent for <head>', function() {
15+
expect(this.html).match(/\n<head/)
1616
})
17-
it('indent <body>', function() {
18-
expect(this.html).match(/\n {2}<body/)
17+
it('no indent for <body>', function() {
18+
expect(this.html).match(/\n<body/)
1919
})
20-
it('indent .sg-section-hello', function() {
21-
expect(this.html).match(/\n {6}<section class="sg-block sg-section-hello/)
22-
})
23-
it('indent .sg-canvas', function() {
24-
expect(this.html).match(/\n {10}<div class="sg-canvas/)
25-
})
26-
})
27-
28-
describe('custom indentSize', function() {
29-
beforeEach(function() {
30-
this.load("### Hello\n\n @example\n div", {
31-
tabWidth: 4
32-
})
33-
})
34-
3520
it('indent .sg-section-hello', function() {
3621
expect(this.html).match(/<section class="sg-block sg-section-hello/)
3722
})
3823
it('indent .sg-canvas', function() {
39-
expect(this.html).match(/\n {8}<div class="sg-canvas/)
24+
expect(this.html).match(/<div class="sg-canvas/)
4025
})
4126
})
4227
})

0 commit comments

Comments
 (0)