Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash change docs #1168

Merged
merged 5 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Copy link
Member

@styfle styfle Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think the urls to md files should being with a slash #/README.md#specifications.
This is a common pattern for js routers so that you know its linking to a different route and not a normal anchor on the page. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We determine whether it is a route or anchor by the existence of /.md$/ but we could change it to /^\\/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also realized, we can use #/README and drop the .md altogether which will read a little bit better.

|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 |
|:-------------|:---------------------------------------------------|
Expand Down Expand Up @@ -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).
8 changes: 4 additions & 4 deletions docs/PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
3. The patch will tend to be more analagous to a `minor` release.
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<h2 id="specifications">Supported Markdown specifications</h2>

Expand All @@ -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).

<h2 id="contributing">Contributing</h2>

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).

<h2 id="authors">Authors</h2>

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).

<h2 id="license">License</h2>

Expand Down
85 changes: 49 additions & 36 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<body>
<div id="container">
<header>
<a href="README.md">
<a href="#">
<img src="img/logo-black.svg" height="64px" width="64px" />
</a>
<h1>Marked.js Documentation</h1>
Expand All @@ -96,49 +96,62 @@ <h1>Marked.js Documentation</h1>
window.fetch = unfetch;
}

if (!Element.prototype.closest) {

if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}

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 currentPage = 'README.md';
var currentHash = '';
var renderedPage = '';

function hashChange() {
var hash = location.hash.slice(1);
if (!hash) {
hash = 'README.md';
}

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, "/");
} else {
currentHash = uri[0];
}
}, false);

fetchPage(currentPage)
.then(function () {
if(currentHash) {
var hashElement = document.getElementById(currentHash);
if (hashElement) {
hashElement.scrollIntoView();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change hashElement.scrollIntoView(); to hashElement.scrollIntoView({ behavior: 'smooth' }); for a buttery transition ⛷️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to work very well.

screenshot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked correctly when you clicked "supported specifications" because that was the only time it hit the scrollIntoView() function as far as I can tell.

}
}
});

history.replaceState('', document.title, '#' + currentPage + (currentHash ? '#' + currentHash : ''));
}

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 (res) {
if (!res.ok) {
throw new Error('Error ' + res.status + ': ' + res.statusText);
}
return res.text();
})
.then(function (text) {
renderedPage = page;
content.innerHTML = marked(text);
body.scrollTop = 0;
}).catch(function (e) {
Expand All @@ -147,7 +160,7 @@ <h1>Marked.js Documentation</h1>
});
}

fetchPage('README.md');
hashChange();
</script>
</body>
</html>