Content-Length: 212197 | pFad | http://github.com/govtrack/linkify-citations/blob/xpath-rewrite/README.md

49 linkify-citations/README.md at xpath-rewrite · govtrack/linkify-citations · GitHub
Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
76 lines (57 loc) · 2.97 KB

README.md

File metadata and controls

76 lines (57 loc) · 2.97 KB

linkify citations

Scans the DOM for legal citations, finds them, and turns them into HTML links.

Usage

<script src="https://s3.amazonaws.com/linkify-citations/linkify.min.js"></script>

Advanced Usage

You can control where on the page links are inserted, which websites you allow linking to, which page types (web pages, PDFs, and raw HTML) you allow links to, and how the link <a> elements are created by turning off automatic linking and calling the linking function directly.

Here's a simple example assuming you are using jQuery:

<script>
// disable the automatic linking of citations
auto_linkify_citations = false;

window.document.addEventListener("DOMContentLoaded", function() {
  linkify_citations(
    $("#content")[0],
    ["usgpo", "libraryofcongress"]
    );
});
</script>

// load the library
<script src="https://s3.amazonaws.com/linkify-citations/linkify.min.js"></script>

The arguments to linkify_citations are all optional. They are:

  • The DOM element within which to replace links.
  • An array of allowed link targets, in order of preference. The default is the complete list of targets provided by the citation library and preferring links to authoritative sources. The values in this array come from the id attribute of the linker modules in the citation library.
  • An array of allowed link page types, in order of preference. The default is ["landing", "pdf", "html"]. See the documentation for link rendition types.
  • A function that creates <a> elements for the inserted links (see below for example).

Here's a complete example showing the default arguments explicity:

<script>
// disable the automatic linking of citations
auto_linkify_citations = false;

window.document.addEventListener("DOMContentLoaded", function() {
  linkify_citations(
    window.document.body, // where to replace links
    ["usgpo", "house", "nara", "libraryofcongress", "dc_council",
     "cornell_lii", "legislink", "govtrack", "courtlistener",
     "vadecoded"], // targets to allow, in preference order
    ["landing", "pdf", "html"], // allowed target types
    function(link, citation, text, document) { // function to create links
      var a = document.createElement("a");
      a.setAttribute("class", "citation");
      a.setAttribute("href", link.url);
      a.appendChild(document.createTextNode(text));
      return a;
    }
  );
});
</script>

// load the library
<script src="https://s3.amazonaws.com/linkify-citations/linkify.min.js"></script>

Development/deployment

Pull requests merged into master will automatically be deployed to the S3 bucket. To test things out, you might want to try rawgit.

Dependencies

None! Everything is self-contained. Under the hood, a lot of the heavy lifting is done by citation.js (demo).









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/govtrack/linkify-citations/blob/xpath-rewrite/README.md

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy