Skip to content

Commit

Permalink
Save as HTML also exports base css
Browse files Browse the repository at this point in the history
Base css is anything coming from `bootstrap.less`

Fixes atom#232
  • Loading branch information
ArnaudRinquin committed Apr 2, 2015
1 parent 9a2293f commit ecbf789
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/markdown-preview-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ class MarkdownPreviewView extends ScrollView

getMarkdownPreviewCSS: ->
markdowPreviewRules = []
ruleRegExp = /\.markdown-preview/
packageRuleCSSRegExp = /\.markdown-preview/
baseCSSRegExp = /bootstrap\.less$/
cssUrlRefExp = /url\(atom:\/\/markdown-preview\/assets\/(.*)\)/

for stylesheet in @getDocumentStyleSheets()
if stylesheet.rules?
isBaseCSS = stylesheet.ownerNode?.sourcePath?.match(baseCSSRegExp)?
for rule in stylesheet.rules
# We only need `.markdown-review` css
markdowPreviewRules.push(rule.cssText) if rule.selectorText?.match(ruleRegExp)?
# We only need `.markdown-review` css and base css
markdowPreviewRules.push(rule.cssText) if isBaseCSS || rule.selectorText?.match(packageRuleCSSRegExp)?

markdowPreviewRules
.concat(@getTextEditorStyles())
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/saved-html.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>code-block</title>
<style>.markdown-preview { color: orange; }
.markdown-preview .host { color: purple; }
basecss { color: pink; }
pre.editor-colors .line { color: brown; }
pre.editor-colors .number { color: cyan; }
pre.editor-colors .host .something { color: black; }
Expand Down
7 changes: 7 additions & 0 deletions spec/markdown-preview-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ describe "MarkdownPreviewView", ->
createRule ".not-included", "{ color: green; }"
createRule ".markdown-preview :host", "{ color: purple; }"
]
}, {
rules: [
createRule "basecss", "{ color: pink; }"
],
ownerNode: {
sourcePath: "/anywhere/bootstrap.less"
}
}
]

Expand Down

0 comments on commit ecbf789

Please sign in to comment.