gatsby-remark-autolink-headers
Advanced tools
Comparing version 1.5.0-alpha.3f307d61 to 1.5.0-alpha.5182142b
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
var scrollToHash = function scrollToHash(offsetY) { | ||
@@ -7,4 +5,6 @@ // Make sure React has had a chance to flush to DOM first. | ||
var hash = window.decodeURI(window.location.hash.replace("#", "")); | ||
if (hash !== "") { | ||
var element = document.getElementById(hash); | ||
if (element) { | ||
@@ -20,7 +20,9 @@ var offset = element.offsetTop; | ||
var offsetY = 0; | ||
if (pluginOptions.offsetY) { | ||
offsetY = pluginOptions.offsetY; | ||
} | ||
// This code is only so scrolling to header hashes works in development. | ||
} // This code is only so scrolling to header hashes works in development. | ||
// For production, the equivalent code is in gatsby-ssr.js. | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -33,2 +35,3 @@ scrollToHash(offsetY); | ||
var offsetY = 0; | ||
if (pluginOptions.offsetY) { | ||
@@ -35,0 +38,0 @@ offsetY = pluginOptions.offsetY; |
"use strict"; | ||
var _react = require("react"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _react = _interopRequireDefault(require("react")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.onRenderBody = function (_ref, pluginOptions) { | ||
var setHeadComponents = _ref.setHeadComponents; | ||
var offsetY = 0; | ||
var offsetY = 0; | ||
if (pluginOptions.offsetY) { | ||
@@ -18,13 +16,12 @@ offsetY = pluginOptions.offsetY; | ||
var styles = "\n .anchor {\n float: left;\n padding-right: 4px;\n margin-left: -20px;\n }\n h1 .anchor svg,\n h2 .anchor svg,\n h3 .anchor svg,\n h4 .anchor svg,\n h5 .anchor svg,\n h6 .anchor svg {\n visibility: hidden;\n }\n h1:hover .anchor svg,\n h2:hover .anchor svg,\n h3:hover .anchor svg,\n h4:hover .anchor svg,\n h5:hover .anchor svg,\n h6:hover .anchor svg {\n visibility: visible;\n }\n "; | ||
var script = "\n document.addEventListener(\"DOMContentLoaded\", function(event) {\n var hash = window.decodeURI(location.hash.replace('#', ''))\n if (hash !== '') {\n var element = document.getElementById(hash)\n if (element) {\n var offset = element.offsetTop\n // Wait for the browser to finish rendering before scrolling.\n setTimeout((function() {\n window.scrollTo(0, offset - " + offsetY + ")\n }), 0)\n }\n }\n })\n "; | ||
return setHeadComponents([_react2.default.createElement( | ||
"style", | ||
{ key: "gatsby-remark-autolink-headers-style", type: "text/css" }, | ||
styles | ||
), _react2.default.createElement("script", { | ||
return setHeadComponents([_react.default.createElement("style", { | ||
key: "gatsby-remark-autolink-headers-style", | ||
type: "text/css" | ||
}, styles), _react.default.createElement("script", { | ||
key: "gatsby-remark-autolink-headers-script", | ||
dangerouslySetInnerHTML: { __html: script } | ||
dangerouslySetInnerHTML: { | ||
__html: script | ||
} | ||
})]); | ||
}; |
10
index.js
@@ -1,5 +0,5 @@ | ||
"use strict"; | ||
var toString = require("mdast-util-to-string"); | ||
var toString = require("mdast-util-to-string"); | ||
var visit = require("unist-util-visit"); | ||
var slugs = require("github-slugger")(); | ||
@@ -14,11 +14,9 @@ | ||
} | ||
module.exports = function (_ref) { | ||
var markdownAST = _ref.markdownAST; | ||
slugs.reset(); | ||
visit(markdownAST, "heading", function (node) { | ||
var id = slugs.slug(toString(node)); | ||
var data = patch(node, "data", {}); | ||
patch(data, "id", id); | ||
@@ -29,3 +27,2 @@ patch(data, "htmlAttributes", {}); | ||
patch(data.hProperties, "id", id); | ||
node.children.unshift({ | ||
@@ -48,4 +45,3 @@ type: "link", | ||
}); | ||
return markdownAST; | ||
}; |
{ | ||
"name": "gatsby-remark-autolink-headers", | ||
"description": "Gatsby plugin to autolink headers in markdown processed by Remark", | ||
"version": "1.5.0-alpha.3f307d61", | ||
"version": "1.5.0-alpha.5182142b", | ||
"author": "Kyle Mathews <mathews.kyle@gmail.com>", | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"@babel/runtime": "^7.0.0-beta.38", | ||
"github-slugger": "^1.1.1", | ||
@@ -13,3 +13,4 @@ "mdast-util-to-string": "^1.0.2", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"@babel/cli": "^7.0.0-beta.38", | ||
"@babel/core": "^7.0.0-beta.38", | ||
"cross-env": "^5.0.5" | ||
@@ -25,6 +26,6 @@ }, | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"watch": "babel -w src --out-dir . --ignore __tests__", | ||
"build": "babel src --out-dir . --ignore ./**/__tests__/", | ||
"watch": "babel -w src --out-dir . --ignore ./**/__tests__/", | ||
"prepublish": "cross-env NODE_ENV=production npm run build" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5381
3
90
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)