From 6ad981e3e571ed980f367a9756064874356f2048 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 27 Mar 2018 10:19:31 -0500 Subject: [PATCH 1/5] use hash change --- docs/index.html | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/index.html b/docs/index.html index 3e2e8450a8..ebb3ccab14 100644 --- a/docs/index.html +++ b/docs/index.html @@ -73,7 +73,7 @@
- +

Marked.js Documentation

@@ -96,44 +96,44 @@

Marked.js Documentation

window.fetch = unfetch; } - if (!Element.prototype.closest) { + var content = document.querySelector('#content'); + var body = document.querySelector('html'); + var currentPage = ''; + var currentHash = ''; - if (!Element.prototype.matches) { - Element.prototype.matches = Element.prototype.msMatchesSelector || - Element.prototype.webkitMatchesSelector; + function hashChange(e) { + var hash = location.hash.slice(1); + if (!hash) { + hash = 'README.md'; } - Element.prototype.closest = function(s) { - var el = this; - if (!document.documentElement.contains(el)) return null; - do { - if (el.matches(s)) return el; - el = el.parentElement || el.parentNode; - } while (el !== null && el.nodeType === 1); - return null; - }; - } - - var content = document.querySelector('#content'); - var body = document.querySelector('html'); + var uri = hash.split('#'); - body.addEventListener('click', function (e) { - var a = e.target.closest('a'); - if (a && a.href.indexOf(location.origin) === 0) { - var uri = a.href.slice(location.origin.length + location.pathname.length).split('#'); - - if (uri[0].match('.md$')) { - e.preventDefault(); - fetchPage(uri[0]) - .then(function () { - if (uri.length > 1) { - location.hash = uri[1]; - } - }); + if (uri[0].match('.md$')) { + currentPage = uri[0]; + if (uri.length > 1) { + currentHash = uri[1]; + } else { + currentHash = ''; } - history.replaceState("", document.title, "/"); + e && e.preventDefault(); + fetchPage(uri[0]) + .then(function () { + if(currentHash) { + var hashElement = document.getElementById(currentHash); + if (hashElement) { + hashElement.scrollIntoView(); + } + } + }); + } else { + currentHash = uri[0]; } - }, false); + + history.replaceState('', document.title, '#' + currentPage + (currentHash ? '#' + currentHash : '')); + } + + window.addEventListener('hashchange', hashChange); function fetchPage(page) { return fetch(page) @@ -147,7 +147,7 @@

Marked.js Documentation

}); } - fetchPage('README.md'); + hashChange(); From 8c6e9d6b9c2f76b41aa55241db475bc055278459 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 27 Mar 2018 10:19:41 -0500 Subject: [PATCH 2/5] update links --- docs/CODE_OF_CONDUCT.md | 2 +- docs/CONTRIBUTING.md | 8 ++++---- docs/PUBLISHING.md | 8 ++++---- docs/README.md | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md index 077c0fc708..d766ea0ac8 100644 --- a/docs/CODE_OF_CONDUCT.md +++ b/docs/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team by submitting a PR with changes to the [AUTHORS](AUTHORS.md) page (or emailing josh@8fold.com). All +reported by contacting the project team by submitting a PR with changes to the [AUTHORS](#AUTHORS.md) page (or emailing josh@8fold.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 1b624126ba..028f42a746 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -25,15 +25,15 @@ The following table lists the ticket type labels we use when there is work to be |Ticket type label |Description | |:----------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |L0 - security |A security vulnerability within the Marked library is discovered. | -|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](README.md#specifications) OR causes marked to crash AND there is no known workaround for the issue. | +|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](#README.md#specifications) OR causes marked to crash AND there is no known workaround for the issue. | |L2 - annoying |Similar to L1 - broken only there is a known workaround avaialable for the issue. | |RR - refactor and re-engineer |Results in an improvement to developers using Marked (improved readability) or end-users (faster performance) or both. | -|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](README.md#specifications) | +|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#README.md#specifications) | |NFU - new feature (user requested) |A capability Marked does not currently provide but has been requested by users of Marked. | ## Test early, often, and everything -We try to write test cases to validate output (writing tests based on the [supported specifications](README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness. +We try to write test cases to validate output (writing tests based on the [supported specifications](#README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness. |Location |Description | |:-------------|:---------------------------------------------------| @@ -92,4 +92,4 @@ npm run build ## Publishing -Creating GitHub releases and publishing to NPM is limited to conributors and owners. If you would like more information, please see our [publishing documentation](PUBLISHING.md). +Creating GitHub releases and publishing to NPM is limited to conributors and owners. If you would like more information, please see our [publishing documentation](#PUBLISHING.md). diff --git a/docs/PUBLISHING.md b/docs/PUBLISHING.md index 4732fdf748..90bad8ef87 100644 --- a/docs/PUBLISHING.md +++ b/docs/PUBLISHING.md @@ -1,6 +1,6 @@ # Releasing Marked -- [ ] See [contributing](CONTRIBUTING.md) +- [ ] See [contributing](#CONTRIBUTING.md) - [ ] Create release branch from `master` (`release-x.y.z`) - [ ] Submit PR with minimal name: Release x.y.z - [ ] Complete PR checklists @@ -13,12 +13,12 @@ We follow [semantic versioning](https://semver.org) where the following sequence is true `[major].[minor].[patch]`; therefore, consider the following implications of the release you are preparing: -1. **Major:** There is at least one change not deemed backward compatible. -2. **Minor:** There is at least one new feature added to the release. +1. **Major:** There is at least one change not deemed backward compatible. +2. **Minor:** There is at least one new feature added to the release. 3. **Patch:** No breaking changes, no new features. What to expect while Marked is a zero-major (0.x.y): 1. The major will remain at zero; thereby, alerting consumers to the potentially volatile nature of the package. 2. The minor will tend to be more analagous to a `major` release. For example, we plan to release `0.4.0` once we have fixed most, if not all, known issues related to the CommonMark and GFM specifications because the architecture changes planned during `0.4.0` will most likely introduce breaking changes. -3. The patch will tend to be more analagous to a `minor` release. \ No newline at end of file +3. The patch will tend to be more analagous to a `minor` release. diff --git a/docs/README.md b/docs/README.md index 42440ce5e5..794716bcc7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,7 +70,7 @@ $ cat hello.html ``` -Marked offers [advanced configurations](USING_ADVANCED.md) and [extensibility](USING_PRO.md) as well. +Marked offers [advanced configurations](#USING_ADVANCED.md) and [extensibility](#USING_PRO.md) as well.

Supported Markdown specifications

@@ -88,17 +88,17 @@ By supporting the above Markdown flavors, it's possible that Marked can help you The only completely secure system is the one that doesn't exist in the first place. Having said that, we take the security of Marked very seriously. -Therefore, please disclose potential security issues by email to the project [committers](AUTHORS.md) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue). +Therefore, please disclose potential security issues by email to the project [committers](#AUTHORS.md) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue).

Contributing

-The marked community enjoys a spirit of collaboration and contribution from all comers. Whether you're just getting started with Markdown, JavaScript, and Marked or you're a veteran with it all figured out, we're here to help each other improve as professionals while helping Marked improve technically. Please see our [contributing documentation](CONTRIBUTING.md) for more details. +The marked community enjoys a spirit of collaboration and contribution from all comers. Whether you're just getting started with Markdown, JavaScript, and Marked or you're a veteran with it all figured out, we're here to help each other improve as professionals while helping Marked improve technically. Please see our [contributing documentation](#CONTRIBUTING.md) for more details. For our Contribution License Agreement, see our [license](https://github.com/markedjs/marked/blob/master/LICENSE.md).

Authors

-For list of credited authors and contributors, please see our [authors page](AUTHORS.md). +For list of credited authors and contributors, please see our [authors page](#AUTHORS.md).

License

From 56d7f752496a6e5f173306ffe1ab655c0feacc00 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 27 Mar 2018 10:34:52 -0500 Subject: [PATCH 3/5] fix initial hash not .md --- docs/index.html | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/index.html b/docs/index.html index ebb3ccab14..23c81d7673 100644 --- a/docs/index.html +++ b/docs/index.html @@ -98,10 +98,11 @@

Marked.js Documentation

var content = document.querySelector('#content'); var body = document.querySelector('html'); - var currentPage = ''; + var currentPage = 'README.md'; var currentHash = ''; + var renderedPage = ''; - function hashChange(e) { + function hashChange() { var hash = location.hash.slice(1); if (!hash) { hash = 'README.md'; @@ -116,29 +117,36 @@

Marked.js Documentation

} else { currentHash = ''; } - e && e.preventDefault(); - fetchPage(uri[0]) - .then(function () { - if(currentHash) { - var hashElement = document.getElementById(currentHash); - if (hashElement) { - hashElement.scrollIntoView(); - } - } - }); } else { currentHash = uri[0]; } + fetchPage(currentPage) + .then(function () { + if(currentHash) { + var hashElement = document.getElementById(currentHash); + if (hashElement) { + hashElement.scrollIntoView(); + } + } + }); + history.replaceState('', document.title, '#' + currentPage + (currentHash ? '#' + currentHash : '')); } - window.addEventListener('hashchange', hashChange); + window.addEventListener('hashchange', function (e) { + e.preventDefault(); + hashChange(); + }); function fetchPage(page) { + if (page === renderedPage) { + return Promise.resolve(); + } return fetch(page) .then(function (res) { return res.text(); }) .then(function (text) { + renderedPage = page; content.innerHTML = marked(text); body.scrollTop = 0; }).catch(function (e) { From e66d0c960026b720d15265d9e9c701657624ce08 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 27 Mar 2018 10:52:41 -0500 Subject: [PATCH 4/5] throw error on error --- docs/index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 23c81d7673..f932c3789c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -144,7 +144,12 @@

Marked.js Documentation

return Promise.resolve(); } return fetch(page) - .then(function (res) { return res.text(); }) + .then(function (res) { + if (!res.ok) { + throw new Error('Error ' + res.status + ': ' + res.statusText); + } + return res.text(); + }) .then(function (text) { renderedPage = page; content.innerHTML = marked(text); From b2f0b3c2509f7e8c20adf554d68960ffae5d857c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 27 Mar 2018 14:06:54 -0500 Subject: [PATCH 5/5] add slash at beginning --- docs/CODE_OF_CONDUCT.md | 2 +- docs/CONTRIBUTING.md | 8 ++++---- docs/PUBLISHING.md | 2 +- docs/README.md | 8 ++++---- docs/index.html | 39 ++++++++++++++++++++++----------------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/docs/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md index d766ea0ac8..62d2d6abb4 100644 --- a/docs/CODE_OF_CONDUCT.md +++ b/docs/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team by submitting a PR with changes to the [AUTHORS](#AUTHORS.md) page (or emailing josh@8fold.com). All +reported by contacting the project team by submitting a PR with changes to the [AUTHORS](#/AUTHORS.md) page (or emailing josh@8fold.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 028f42a746..ce5f0c387e 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -25,15 +25,15 @@ The following table lists the ticket type labels we use when there is work to be |Ticket type label |Description | |:----------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |L0 - security |A security vulnerability within the Marked library is discovered. | -|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](#README.md#specifications) OR causes marked to crash AND there is no known workaround for the issue. | +|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](#/README.md#specifications) OR causes marked to crash AND there is no known workaround for the issue. | |L2 - annoying |Similar to L1 - broken only there is a known workaround avaialable for the issue. | |RR - refactor and re-engineer |Results in an improvement to developers using Marked (improved readability) or end-users (faster performance) or both. | -|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#README.md#specifications) | +|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#/README.md#specifications) | |NFU - new feature (user requested) |A capability Marked does not currently provide but has been requested by users of Marked. | ## Test early, often, and everything -We try to write test cases to validate output (writing tests based on the [supported specifications](#README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness. +We try to write test cases to validate output (writing tests based on the [supported specifications](#/README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness. |Location |Description | |:-------------|:---------------------------------------------------| @@ -92,4 +92,4 @@ npm run build ## Publishing -Creating GitHub releases and publishing to NPM is limited to conributors and owners. If you would like more information, please see our [publishing documentation](#PUBLISHING.md). +Creating GitHub releases and publishing to NPM is limited to conributors and owners. If you would like more information, please see our [publishing documentation](#/PUBLISHING.md). diff --git a/docs/PUBLISHING.md b/docs/PUBLISHING.md index 90bad8ef87..99dcbfecf5 100644 --- a/docs/PUBLISHING.md +++ b/docs/PUBLISHING.md @@ -1,6 +1,6 @@ # Releasing Marked -- [ ] See [contributing](#CONTRIBUTING.md) +- [ ] See [contributing](#/CONTRIBUTING.md) - [ ] Create release branch from `master` (`release-x.y.z`) - [ ] Submit PR with minimal name: Release x.y.z - [ ] Complete PR checklists diff --git a/docs/README.md b/docs/README.md index 794716bcc7..f5b154276b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -70,7 +70,7 @@ $ cat hello.html ``` -Marked offers [advanced configurations](#USING_ADVANCED.md) and [extensibility](#USING_PRO.md) as well. +Marked offers [advanced configurations](#/USING_ADVANCED.md) and [extensibility](#/USING_PRO.md) as well.

Supported Markdown specifications

@@ -88,17 +88,17 @@ By supporting the above Markdown flavors, it's possible that Marked can help you The only completely secure system is the one that doesn't exist in the first place. Having said that, we take the security of Marked very seriously. -Therefore, please disclose potential security issues by email to the project [committers](#AUTHORS.md) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue). +Therefore, please disclose potential security issues by email to the project [committers](#/AUTHORS.md) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue).

Contributing

-The marked community enjoys a spirit of collaboration and contribution from all comers. Whether you're just getting started with Markdown, JavaScript, and Marked or you're a veteran with it all figured out, we're here to help each other improve as professionals while helping Marked improve technically. Please see our [contributing documentation](#CONTRIBUTING.md) for more details. +The marked community enjoys a spirit of collaboration and contribution from all comers. Whether you're just getting started with Markdown, JavaScript, and Marked or you're a veteran with it all figured out, we're here to help each other improve as professionals while helping Marked improve technically. Please see our [contributing documentation](#/CONTRIBUTING.md) for more details. For our Contribution License Agreement, see our [license](https://github.com/markedjs/marked/blob/master/LICENSE.md).

Authors

-For list of credited authors and contributors, please see our [authors page](#AUTHORS.md). +For list of credited authors and contributors, please see our [authors page](#/AUTHORS.md).

License

diff --git a/docs/index.html b/docs/index.html index f932c3789c..a985d16f5e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -73,7 +73,7 @@
- +

Marked.js Documentation

@@ -110,8 +110,8 @@

Marked.js Documentation

var uri = hash.split('#'); - if (uri[0].match('.md$')) { - currentPage = uri[0]; + if (uri[0].match(/^\//)) { + currentPage = uri[0].slice(1); if (uri.length > 1) { currentHash = uri[1]; } else { @@ -121,23 +121,23 @@

Marked.js Documentation

currentHash = uri[0]; } - fetchPage(currentPage) - .then(function () { - if(currentHash) { - var hashElement = document.getElementById(currentHash); - if (hashElement) { - hashElement.scrollIntoView(); - } - } - }); + fetchPage(currentPage).then(function () { + fetchAnchor(currentHash) + }); - history.replaceState('', document.title, '#' + currentPage + (currentHash ? '#' + currentHash : '')); + history.replaceState('', document.title, '#/' + currentPage + (currentHash ? '#' + currentHash : '')); } - window.addEventListener('hashchange', function (e) { - e.preventDefault(); - hashChange(); - }); + function fetchAnchor(anchor) { + if (!anchor) { + return; + } + + var hashElement = document.getElementById(anchor); + if (hashElement) { + hashElement.scrollIntoView(); + } + } function fetchPage(page) { if (page === renderedPage) { @@ -160,6 +160,11 @@

Marked.js Documentation

}); } + window.addEventListener('hashchange', function (e) { + e.preventDefault(); + hashChange(); + }); + hashChange();