Skip to content

Commit

Permalink
3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
caiogondim committed Jan 16, 2018
1 parent 688d4c4 commit f7844c1
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 145 deletions.
206 changes: 135 additions & 71 deletions dist/logdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ return /******/ (function(modules) { // webpackBootstrap

var Logdown = __webpack_require__(1)()
var markdown = __webpack_require__(3)
var isColorSupported = __webpack_require__(6)
var globalObject = __webpack_require__(9)()
var isColorSupported = __webpack_require__(5)
var globalObject = __webpack_require__(8)()

//
// Static
Expand Down Expand Up @@ -346,30 +346,42 @@ module.exports = function toArray (arg) {
/* 3 */
/***/ (function(module, exports, __webpack_require__) {

var rules = __webpack_require__(4)
var getNextMatch = __webpack_require__(5)
var Markdown = __webpack_require__(4)

function parse (text) {
var styles = []
var match = getNextMatch(text, rules)
var styles = []

while (match) {
styles.push(match.rule.style)
function createStyledRenderer (style) {
return function (input) {
styles.push(style)
styles.push('') // Empty string resets style.

text = text.replace(match.rule.regexp, match.rule.replacer)
match = getNextMatch(text, rules)
return '%c' + input + '%c'
}
}

var markdown = new Markdown({
renderer: {
'*': createStyledRenderer('font-weight:bold;'),
'_': createStyledRenderer('font-style:italic;'),
'`': createStyledRenderer(
'background-color:rgba(255,204,102, 0.1);' +
'color:#FFCC66;' +
'padding:2px 5px;' +
'border-radius:2px;'
)
}
})

return {
text: text,
styles: styles
function parse (text) {
var result = {
text: markdown.parse(text),
styles: [].concat(styles)
}
}

//
// API
//
styles.length = 0

return result
}

module.exports = {
parse: parse
Expand All @@ -380,79 +392,131 @@ module.exports = {
/* 4 */
/***/ (function(module, exports) {

module.exports = [
{
regexp: /\*([^*]+)\*/,
replacer: function (match, submatch1) {
return '%c' + submatch1 + '%c'
},
style: 'font-weight:bold;'
},
{
regexp: /_([^_]+)_/,
replacer: function (match, submatch1) {
return '%c' + submatch1 + '%c'
},
style: 'font-style:italic;'
},
{
regexp: /`([^`]+)`/,
replacer: function (match, submatch1) {
return '%c' + submatch1 + '%c'
},
style:
'background-color:rgba(255,204,102, 0.1);' +
'color:#FFCC66;' +
'padding:2px 5px;' +
'border-radius:2px;'
var lexemeRe = /([_*`\\]|[^_*`\\]+)/g
var mdTagRe = /[_*`]/

function Markdown (options) {
this.renderer = options.renderer
}

function isMdTag (lexeme) {
return mdTagRe.test(lexeme)
}

Markdown.prototype.parse = function (text) {
var lexemes = text.match(lexemeRe)
var render = this.renderer

var formattedText = ''
var currentScope
var scopesStack = []
var activeScopes = {}
var buffer
var lexeme
var cursor = 0

function drainTillLexeme (lexeme) {
var buffer = ''

while (currentScope && currentScope.tag !== lexeme) {
buffer = currentScope.tag + currentScope.text + buffer
activeScopes[currentScope.tag] = false
currentScope = scopesStack.pop()
}

return buffer
}
]

while (lexeme = lexemes[cursor]) { // eslint-disable-line
buffer = ''
cursor++

if (isMdTag(lexeme)) {
if (activeScopes[lexeme]) {
// we've found matching closing tag
// if we have some other unclosed tags in-between - treat them as a plain text
buffer = drainTillLexeme(lexeme)

// now currentScope holds the scope for the tag (`lexeme`) we are trying to close
buffer = render[currentScope.tag](currentScope.text + buffer)
activeScopes[lexeme] = false
currentScope = scopesStack.pop()
} else {
var initialText = ''

if (lexeme === '`') {
// `code` according to spec has the highest priority
// and does not allow nesting
// looking if we can find the closing delimiter

// NOTE: we have already incremented cursor, so we do not need to add 1
var newCursor = lexemes.indexOf(lexeme, cursor)

if (newCursor !== -1) {
formattedText += drainTillLexeme() // if we already have activeScopes, treat them as plain text
initialText = lexemes.slice(cursor, newCursor).join('')
cursor = newCursor // set cursor to the closing backticks
}
}

/***/ }),
/* 5 */
/***/ (function(module, exports) {
if (currentScope) {
scopesStack.push(currentScope)
}

module.exports = function getNextMatch (text, rules) {
var matches = []
activeScopes[lexeme] = true
currentScope = {
tag: lexeme,
text: initialText
}
}
} else {
buffer = lexeme

rules.forEach(function (rule) {
var match = text.match(rule.regexp)
if (lexeme === '\\') { // process escaping
var nextLexeme = lexemes[cursor]

if (match) {
matches.push({
rule: rule,
match: match
})
if (isMdTag(nextLexeme) || nextLexeme === '\\') {
// ignore next md tag, because it is escaped
buffer = nextLexeme
cursor++
}
}
}
})

if (matches.length === 0) {
return null
if (buffer) {
if (currentScope) {
currentScope.text += buffer
} else {
formattedText += buffer
}

buffer = ''
}
}

matches.sort(function (a, b) {
return a.match.index - b.match.index
})
// get the rest of the unclosed tags
formattedText += drainTillLexeme()

return matches[0]
return formattedText
}

module.exports = Markdown


/***/ }),
/* 6 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {

var isWebkit = __webpack_require__(7)
var isFirefox = __webpack_require__(8)
var isWebkit = __webpack_require__(6)
var isFirefox = __webpack_require__(7)

module.exports = function isColorSupported () {
return (isWebkit() || isFirefox())
}


/***/ }),
/* 7 */
/* 6 */
/***/ (function(module, exports) {

// Is webkit? http://stackoverflow.com/a/16459606/376773
Expand All @@ -466,7 +530,7 @@ module.exports = function isWebkit () {


/***/ }),
/* 8 */
/* 7 */
/***/ (function(module, exports) {

module.exports = function isFirefox () {
Expand All @@ -479,7 +543,7 @@ module.exports = function isFirefox () {


/***/ }),
/* 9 */
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(global) {/* eslint-disable no-new-func */
Expand All @@ -499,10 +563,10 @@ function getGlobal (slf, glb) {
module.exports = getGlobal.bind(this, self, global)
module.exports.getGlobal = getGlobal

/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10)))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9)))

/***/ }),
/* 10 */
/* 9 */
/***/ (function(module, exports) {

var g;
Expand Down
2 changes: 1 addition & 1 deletion dist/logdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/logdown.min.js.gzip
Binary file not shown.
Loading

0 comments on commit f7844c1

Please sign in to comment.