Sha256: 0fe2b2c2fa69118a3eefdc6fb2254199880bcbea1d5d9551331987b70c2978e2

Contents?: true

Size: 836 Bytes

Versions: 19

Compression:

Stored size: 836 Bytes

Contents

Tools = require '../_tools'

module.exports = class Tools.Referencer

  constructor: (@environment) ->

  resolve: (text, replacer) ->
    # Make curly braces within code blocks undetectable
    text = text.replace /\`[^\`]*\`/mg, (match) -> match.replace(/\{/mg, "\u0091").replace(/\}/mg, "\u0092")

    # Search for references and replace them
    text = text.replace /\{([^\}]*)\}/gm, (match, link) =>
      link  = link.split(' ')
      href  = link.shift()
      label = link.join(' ')

      replacement = @environment.reference(href)

      if replacement != href || /\:\/\/\w+((\:\d+)?\/\S*)?/.test(href)
        replacer replacement, label || href
      else
        match

    # Restore curly braces within code blocks
    text = text.replace /\`[^\`]*\`/mg, (match) -> match.replace(/\u0091/mg, '{').replace(/\u0092/mg, '}')

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.5 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.4 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.3 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.2 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.1 node_modules/codo/lib/tools/referencer.coffee
ela-4.1.0 node_modules/codo/lib/tools/referencer.coffee
ela-4.0.0 node_modules/codo/lib/tools/referencer.coffee
ela-3.4.3 node_modules/codo/lib/tools/referencer.coffee
ela-3.4.2 node_modules/codo/lib/tools/referencer.coffee
ela-3.4.0 node_modules/codo/lib/tools/referencer.coffee
ela-3.3.1 node_modules/codo/lib/tools/referencer.coffee
ela-3.3.0 node_modules/codo/lib/tools/referencer.coffee
ela-3.2.0 node_modules/codo/lib/tools/referencer.coffee
ela-3.1.1 node_modules/codo/lib/tools/referencer.coffee
ela-3.1.0 node_modules/codo/lib/tools/referencer.coffee
ela-3.0.0 node_modules/codo/lib/tools/referencer.coffee
ela-2.0.0 node_modules/codo/lib/tools/referencer.coffee
ela-1.1.0 node_modules/codo/lib/tools/referencer.coffee