How to use the @markedjs/html-differ.HtmlDiffer function in @markedjs/html-differ

To help you get started, we’ve selected a few @markedjs/html-differ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marktext / marktext / test / specs / commonMark / run.spec.js View on Github external
// This file is copy from marked and modified.
import { removeCustomClass, padding } from '../help'
import { MT_MARKED_OPTIONS } from '../config'
const fetch = require('node-fetch')
const markedJs = require('marked')
const marked = require('../../../src/muya/lib/parser/marked/index.js').default
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer
const fs = require('fs')
const path = require('path')

const options = { ignoreSelfClosingSlash: true, ignoreAttributes: ['id', 'class'] }

const htmlDiffer = new HtmlDiffer(options)

const getSpecs = async () => {
  const version = await fetch('https://raw.githubusercontent.com/commonmark/commonmark.js/master/package.json')
    .then(res => res.json())
    .then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1'))

  return fetch(`https://spec.commonmark.org/${version}/spec.json`)
    .then(res => res.json())
    .then(specs => ({ specs, version }))
}

const getMarkedSpecs = async (version) => {
  return fetch(`https://raw.githubusercontent.com/markedjs/marked/master/test/specs/commonmark/commonmark.${version}.json`)
    .then(res => res.json())
}
github marktext / marktext / test / specs / gfm / run.spec.js View on Github external
// This file is copy from https://github.com/markedjs/marked/blob/master/test/specs/gfm/getSpecs.js
// And for custom use.
import { removeCustomClass } from '../help'
import { writeResult } from '../commonMark/run.spec'
import { MT_MARKED_OPTIONS } from '../config'
const fetch = require('node-fetch')
const cheerio = require('cheerio')
const marked = require('../../../src/muya/lib/parser/marked/index.js').default
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer
const fs = require('fs')
const path = require('path')

const options = { ignoreSelfClosingSlash: true, ignoreAttributes: ['id', 'class'] }

const htmlDiffer = new HtmlDiffer(options)

const getSpecs = () => {
  return fetch('https://github.github.com/gfm/')
    .then(res => res.text())
    .then(html => cheerio.load(html))
    .then($ => {
      const version = $('.version').text().match(/\d+\.\d+/)[0]
      if (!version) {
        throw new Error('No version found')
      }
      const specs = []
      $('.extension').each((i, ext) => {
        const section = $('.definition', ext).text().trim().replace(/^\d+\.\d+(.*?) \(extension\)[\s\S]*$/, '$1')
        $('.example', ext).each((j, exa) => {
          const example = +$(exa).attr('id').replace(/\D/g, '')
          const markdown = $('.language-markdown', exa).text().trim()
github markedjs / marked / test / specs / marked / marked-spec.js View on Github external
/**
 * Marked does not have a custom markdown specification. However, there are times
 * when we come across use cases that are not defined in a given specification.
 * Therefore, we will put use cases together to illustrate those instances to
 * consumers of marked.
 *
 */
var marked = require('../../../lib/marked.js');
var markedSpec = require('./marked.json');
var HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer,
    htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true});
var since = require('jasmine2-custom-message');

var Messenger = function() {};

Messenger.prototype.message = function(spec, expected, actual) {
  return 'CommonMark (' + spec.section + '):\n' + spec.markdown + '\n------\n\nExpected:\n' + expected + '\n------\n\nMarked:\n' + actual;
};

Messenger.prototype.test = function(spec, section, ignore) {
  if (spec.section === section) {
    var shouldFail = ~ignore.indexOf(spec.example);
    it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() {
      var expected = spec.html;
      var actual = marked(spec.markdown, { headerIds: false, xhtml: true });
      since(messenger.message(spec, expected, actual)).expect(
        htmlDiffer.isEqual(expected, actual)
github markedjs / marked / test / specs / commonmark / commonmark-spec.js View on Github external
var marked = require('../../../lib/marked.js');
var cmSpec = require('./commonmark.0.28.json');
var HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer,
    htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true});
var since = require('jasmine2-custom-message');

var Messenger = function() {};

Messenger.prototype.message = function(spec, expected, actual) {
  return 'CommonMark (' + spec.section + '):\n' + spec.markdown + '\n------\n\nExpected:\n' + expected + '\n------\n\nMarked:\n' + actual;
};

Messenger.prototype.test = function(spec, section, ignore) {
  if (spec.section === section) {
    var shouldFail = ~ignore.indexOf(spec.example);
    it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() {
      var expected = spec.html;
      var actual = marked(spec.markdown, { headerIds: false, xhtml: true });
      since(messenger.message(spec, expected, actual)).expect(
        htmlDiffer.isEqual(expected, actual)
github markedjs / marked / test / specs / gfm / gfm-spec.js View on Github external
var marked = require('../../../lib/marked.js');
var gfmSpec = require('./gfm.0.28.json');
var HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer,
    htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true});
var since = require('jasmine2-custom-message');

var Messenger = function() {};

Messenger.prototype.message = function(spec, expected, actual) {
  return 'CommonMark (' + spec.section + '):\n' + spec.markdown + '\n------\n\nExpected:\n' + expected + '\n------\n\nMarked:\n' + actual;
};

Messenger.prototype.test = function(spec, section, ignore) {
  if (spec.section === section && ignore.indexOf(spec.example) < 0) {
    var shouldFail = ~ignore.indexOf(spec.example);
    it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() {
      var expected = spec.html;
      var actual = marked(spec.markdown, { headerIds: false, xhtml: false });
      since(messenger.message(spec, expected, actual)).expect(
        htmlDiffer.isEqual(expected, actual)
github markedjs / marked / test / helpers / html-differ.js View on Github external
const HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer;
const htmlDiffer = new HtmlDiffer({ ignoreSelfClosingSlash: true });

module.exports = {
  isEqual: htmlDiffer.isEqual.bind(htmlDiffer),
  firstDiff: async(actual, expected, padding) => {
    padding = padding || 30;
    const diffHtml = await htmlDiffer.diffHtml(actual, expected);
    const result = diffHtml.reduce((obj, diff) => {
      if (diff.added) {
        if (obj.firstIndex === null) {
          obj.firstIndex = obj.expected.length;
        }
        obj.expected += diff.value;
      } else if (diff.removed) {
        if (obj.firstIndex === null) {
          obj.firstIndex = obj.actual.length;
        }

@markedjs/html-differ

Compares two HTML

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis

Popular @markedjs/html-differ functions