GithubHelp home page GithubHelp logo

remarkjs / remark-autolink-headings Goto Github PK

View Code? Open in Web Editor NEW
65.0 65.0 15.0 134 KB

Legacy remark plugin to automatically add links to headings — please use `rehype-autolink-headings` instead

Home Page: https://unifiedjs.com

License: MIT License

JavaScript 100.00%
autolink heading link remark remark-plugin

remark-autolink-headings's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

remark-autolink-headings's Issues

latin char id link problem

in my language charter ş,iü,ğ ex. latin char not translate #id link .maybe use slugify package for address solved the problem

Links should either be labeled or removed from tabbing

Subject of the issue

Generated header links are given an aria-hidden attribute, which removes them from the accessibility tree. If that is the goal, then they should also have a tabindex of -1. Currently, when a user tabs into a header link, VoiceOver reads back the name of the document rather than the heading text.

Alternatively (and, I believe, a better experience), you could consider either:

  • Wrapping the link around the heading's text rather than having it adjacent to the text (and unhide it)
<h2 id="what-exactly-is-a-portal">
  <a href="#what-exactly-is-a-portal">
    <span class="icon icon-link"></span>What exactly is a portal?
  </a>
</h2>
  • Adding an aria-labelledby attribute that points back to the generated ID of the heading.
<h2 id="what-exactly-is-a-portal">
  <a href="#what-exactly-is-a-portal" aria-labelledby="what-exactly-is-a-portal">
    <span class="icon icon-link"></span>
  </a>What exactly is a portal?
</h2>

The latter won't be as widely supported, but the former will probably require breaking a lot of existing projects and a new approach for handling styles. I'd probably suggest #2 until introducing a new major version.

I'm happy to submit a PR if someone wants to weigh in on the preferred approach here!

Your environment

  • MacOS Catalina w/ VoiceOver
  • N/A
  • N/A

Steps to reproduce

Enable VoiceOver under Accessibility settings in System Preferences and tab through a site with generated headers.

Expected behaviour

Screen readers should read back what's in the heading when it receives focus, or they should be removed from focus altogether

Actual behaviour

Screen readers announce the title of the page or active landmark if one exists, creating a confusing experience.

Support ignoring headings

Are you open to an option to ignore certain headings?

I'd really like to ignore h1's for example (as they're generally the top level and basically a post title).

something like { ignore: [ 1 ] } would be perfect.

I have a possible PR but wanted to check if you were open to it.

Add behavoir for fixed headers.

To avoid heading overlapping by fixed header it needs to move anchor link upper on header size. There is no way to make it works with this lib, so I needed to make my own plugin. It will be nice if you will add support out of the box.

Here is code

const visit = require('unist-util-visit');

function inject(node, id) {
  delete node.data.hProperties.id;

  const text = node.children[0] && node.children[0].value;
  node.data.hChildren = [
    { // the anchor
      type: 'element',
      tagName: 'a',
      properties: { id, className: ['anchor-link'] },
    },
    { // heading text
      type: 'text',
      value: text,
    },
    { // "#" symbol for linking
      type: 'element',
      tagName: 'a',
      children: [{ type: 'text', value: '#' }],
      properties: { href: '#' + id, className: ['anchor-link-style'] },
    },
  ];
}

module.exports = () => (tree, file) => {
  visit(tree, 'heading', node => {
    const { data } = node;
    const id = data && data.hProperties && data.hProperties.id;

    if (id) {
      inject(node, id);
    }
  });
};

And then in css

h1, h2, h3, h4, h5, h6 {
  position: relative
}

.anchor-link {
  position: absolute;
  top: -60px;
}

Generated link anchor doesn't have an icon

Subject of the issue

The generated link doesn't have any link icon and zero width when it gets appended/prepended to the heading.

So the DOM is technically correct, but there is no way to click for the user to jump to the selected anchor.

Are we supposed to add a link icon ourselves and attach it to the .link.icon class on the span element?

Expected behaviour

Nice link icon to click

Actual behaviour

Unclickable anchor link

Emoji leads to weird slug

screen shot 2016-08-30 at 12 45 47

Watch carfully the hovered link (it looks good), but when clicking, I got a weird URL. I assume that the emoji is still here, but hidden.

It seems that remark-slug is ok as you can see in the HTML. Ref remarkjs/remark-slug#2

Include example on how to style <span class="icon icon-link">

Subject of the feature

Missing documentation on how to style the link so it is visible.

Problem

It is unclear on how to style the icon icon-link. Would be good if the readme documents an example on how to style this to have the link show up in front of the headings.

Expected behavior

Documentation/README shows some example on how to style the icon-links.

Alternatives

Include an SVG in the span that is rendered by default.

No Id, No href attribute

I imported the plugin and added use(headings) in remark. It didn't add any id or href attribute in the headings tag.

am I missing something?

import headings from "remark-autolink-headings";

export async function getPostData(id: string) {
  const fullPath = path.join(postsDirectory, `${id}.md`);
  const fileContents = fs.readFileSync(fullPath, "utf8");

  const matterResult = matter(fileContents);
  const processedContent = await remark()
    .use(headings)
    .use(highlight)
    .use(html)
    .process(matterResult.content);

  const contentHtml = processedContent.toString();

  return {
    id,
    contentHtml,
    ...(matterResult.data as {
      date: string;
      title: string;
      cover: string;
      tags: string[];
      author: string;
    }),
  };
}

Links are not added to headings

I just tried the example from the README, and no links are added to the html.

I've created a repo demonstrating the issue https://github.com/rigor789/remark-autolink-headings-issue

Is there something I missed?

In the meantime I'll dig deeper, and submit a PR if I figure it out

Edit:

Looks like htmlAttributes has been deprecated and replaced with hProperties.

remark-slug has been updated to use hProperties and this needs to be updated as well.

PR is on it's way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.