Sha256: f478f852f561655a0ffdfefb626c880cd6ce9d464aee14ca8dcd917d3214a78b

Contents?: true

Size: 1.23 KB

Versions: 43

Compression:

Stored size: 1.23 KB

Contents

//////////////////////////////
// Tree Abstraction
//////////////////////////////
'use strict';

var gonzales = require('gonzales-pe-sl');
var fm = require('front-matter');
var helpers = require('./helpers');

module.exports = function (text, syntax, filename) {
  var tree;

  // Run `.toString()` to allow Buffers to be passed in
  text = helpers.stripBom(text.toString());

  // if we're skipping front matter do it here, fall back to just our text in case it fails
  if (fm.test(text)) {
    var withFrontMatter = fm(text);
    // Replace front matter by empty lines, so that line numbers are preserved
    var numEmptyLines = 2;
    if (withFrontMatter.frontmatter !== '') {
      numEmptyLines += withFrontMatter.frontmatter.split('\r\n|\r|\n').length;
    }
    var emptyLines = new Array(numEmptyLines + 1).join('\n');
    text = emptyLines + withFrontMatter.body || text;
  }

  try {
    tree = gonzales.parse(text, {
      'syntax': syntax
    });
  }
  catch (e) {
    throw {
      message: e.message,
      file: filename,
      line: e.line
    };
  }

  if (typeof tree === 'undefined') {
    throw {
      message: 'Undefined tree',
      file: filename,
      text: text.toString(),
      tree: tree.toString()
    };
  }

  return tree;
};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.21.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.20.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.19.1 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.19.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.18.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.17.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.16.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.15.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.14.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.13.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.12.2 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.12.1 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.12.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.11.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.10.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.9.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.8.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.7.0 node_modules/sass-lint/lib/groot.js
govuk_publishing_components-17.6.1 node_modules/sass-lint/lib/groot.js