Giter Club home page Giter Club logo

downlit's Introduction

downlit

R build status Codecov test coverage CRAN status

The goal of downlit is to provide syntax highlighting and automatic linking of R code in a way that is easily used from RMarkdown packages like pkgdown, bookdown, and hugodown.

Installation

Install downlit from CRAN with:

install.packages("downlit")

Features

downlit has two slightly different highlighting/linking engines:

  • highlight() works with multiline code blocks and does syntax highlighting, function linking, and comment styling.
  • autolink() works with inline code and only does linking.

Multiline code blocks have:

  • Code syntax highlighted using R's parser.
  • Function calls automatically linked to their corresponding documentation.
  • Comments styled by transforming ANSI escapes sequences to their HTML equivalents (thanks fansi package).

The following forms of inline code are recognized and automatically linked:

  • fun(), pkg::fun().
  • ?fun, pkg::fun, type?topic.
  • help("fun"), help("fun", package = "package"), help(package = "package").
  • vignette("name"), vignette("name", package = "package").
  • library(package), require(package), requireNamespace("package").
  • {package} gets linked (if possible) and formatted as plain text.

Cross-package links

If downlit can find a pkgdown site for the remote package, it will link to it; otherwise it will link to https://rdrr.io/ for documentation, and CRAN for vignettes. In order for a pkgdown site to be findable, it needs to be listed in two places:

  • In the URL field in the DESCRIPTION, as in dplyr:

    URL: https://dplyr.tidyverse.org, https://github.com/tidyverse/dplyr
    
  • In the url field in _pkgdown.yml, as in dplyr

    url: https://dplyr.tidyverse.org

    When this field is defined, pkgdown generates a public facing pkgdown.yml file that provides metadata about the site:

    pandoc: '2.2'
    pkgdown: 1.3.0
    pkgdown_sha: ~
    articles:
      compatibility: compatibility.html
      dplyr: dplyr.html
    urls:
      reference: https://dplyr.tidyverse.org/reference
      article: https://dplyr.tidyverse.org/articles

So when you build a pkgdown site that links to the dplyr documentation (e.g., dplyr::mutate()), pkgdown looks first in dplyr's DESCRIPTION to find its website, then it looks for pkgdown.yml, and uses the metadata to generate the correct links.

Usage

downlit is designed to be used by other packages, and I expect most uses of downlit will use it via another package (e.g. hugodown). If you want to use it in your own package, you'll typically want to apply it as part of some bigger transformation process. You can get some sense of how this might work by reading the source code of downlit_html() and downlit_md(), which transform HTML and markdown documents respectively.

downlit's People

Contributors

hadley avatar krlmlr avatar maelle avatar mdneuzerling avatar salim-b avatar strazto avatar

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.