Socket
Socket
Sign inDemoInstall

@tryghost/kg-mobiledoc-html-renderer

Package Overview
Dependencies
Maintainers
15
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tryghost/kg-mobiledoc-html-renderer - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2-4.0.0-rc.0.0

43

lib/mobiledoc-html-renderer.js
const SimpleDom = require('simple-dom');
const semver = require('semver');
const Renderer = require('mobiledoc-dom-renderer').default;

@@ -26,2 +27,25 @@

const slugify = function (inputString, {ghostVersion = '4.0'} = {}) {
const version = semver.coerce(ghostVersion);
if (semver.satisfies(version, '<4.x')) {
// backwards compatible slugs used in Ghost 2.x to 3.x mobiledoc
return inputString.replace(/[<>&"?]/g, '')
.trim()
.replace(/[^\w]/g, '-')
.replace(/-{2,}/g, '-')
.toLowerCase();
} else {
// news slugs introduced in 4.0
// allows all chars except symbols but will urlEncode everything
// produces %-encoded chars in src but browsers show real chars in status bar and url bar
return encodeURIComponent(inputString.trim()
.toLowerCase()
.replace(/[\][!"#$%&'()*+,./:;<=>?@\\^_{|}~]/g, '')
.replace(/\s+/g, '-')
.replace(/^-|-{2,}|-$/g, '')
);
}
};
// used to walk the rendered SimpleDOM output and modify elements before

@@ -31,4 +55,5 @@ // serializing to HTML. Saves having a large HTML parsing dependency such as

class DomModifier {
constructor() {
constructor(options) {
this.usedIds = [];
this.options = options;
}

@@ -42,8 +67,3 @@

let text = nodeTextContent(node);
let id = text
.replace(/[<>&"?]/g, '')
.trim()
.replace(/[^\w]/g, '-')
.replace(/-{2,}/g, '-')
.toLowerCase();
let id = slugify(text, this.options);

@@ -83,8 +103,5 @@ if (this.usedIds[id] !== undefined) {

render(mobiledoc, _cardOptions = {}) {
/**
* version 1 === Ghost 1.0 markdown-only mobiledoc
* version 2 (latest) === Ghost 2.0 full mobiledoc
*/
const ghostVersion = mobiledoc.ghostVersion || '4.0';
const defaultCardOptions = {
version: 2,
ghostVersion,
target: 'html'

@@ -109,3 +126,3 @@ };

// eg. to add ID attributes to heading elements
const modifier = new DomModifier();
const modifier = new DomModifier({ghostVersion});
modifier.modifyChildren(rendered.result);

@@ -112,0 +129,0 @@

{
"name": "@tryghost/kg-mobiledoc-html-renderer",
"version": "3.0.1",
"version": "3.0.2-4.0.0-rc.0.0",
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-mobiledoc-html-renderer",

@@ -26,5 +26,6 @@ "author": "Ghost Foundation",

"mobiledoc-dom-renderer": "^0.7.0",
"semver": "^7.3.4",
"simple-dom": "^1.4.0"
},
"gitHead": "93c853c6be3de6e0dbece24367aeba2089df217e"
"gitHead": "f9a83f9ba1f0fe3fcf4cdffa996a7c8da548226b"
}

@@ -37,4 +37,4 @@ # Koenig Mobiledoc Html Renderer

# Copyright & License
# Copyright & License
Copyright (c) 2020 Ghost Foundation - Released under the [MIT license](LICENSE).
Copyright (c) 2013-2021 Ghost Foundation - Released under the [MIT license](LICENSE).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc