Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanouil committed Jul 14, 2024
0 parents commit 188861a
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: mcanouil
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy

on:
workflow_dispatch:
push:
branches:
- main

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4

- uses: quarto-dev/quarto-actions/setup@v2
with:
version: pre-release
tinytex: true

- name: Render Quarto Project
shell: bash
run: |
quarto render example.qmd --to html --output index.html --output-dir _site
- uses: actions/configure-pages@v5

- uses: actions/upload-pages-artifact@v3
with:
path: '_site'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.html
*.pdf
*_files/
/.luarc.json
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Github Extension For Quarto

`github` is an extension for [Quarto](https://quarto.org) to automatically shortens and converts [GitHub references](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls) into links.

## Installing

```bash
quarto add mcanouil/quarto-github
```

This will install the extension under the `_extensions` subdirectory.
If you're using version control, you will want to check in this directory.

## Using

Add the following to your YAML header:

```yaml
filters:
- github
```
Some references require a default repository to be set via the `repository-name` YAML key.

```yml
repository-name: jlord/sheetsee.js
```

## References

Source: [Autolinked references and URLs - GitHub Docs](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls).

### Issues and pull requests

| Reference type | Raw reference | Short link |
|--------------------------------------------------------------------------------------------|--------------------------------------------------|---------------------------------|
| Issue, discussion, or pull request URL (***`repository-name` is optional!***) | `https://github.com/jlord/sheetsee.js/issues/26` | `#26` or `lord/sheetsee.js#26` |
| `#` and issue, discussion, or pull request number (***`repository-name` is required!***) | `#26` | `#26` |
| `GH-` and issue, discussion, or pull request number (***`repository-name` is required!***) | `GH-26` | `GH-26` |
| `Username/Repository#` and issue, discussion, or pull request number | `jlord/sheetsee.js#26` | `jlord/sheetsee.js#26` |
| `Organization_name/Repository#` and issue, discussion, or pull request number | `github-linguist/linguist#4039` | `github-linguist/linguist#4039` |

## Commit SHAs

| Reference type | Raw reference | Short link |
|---------------------------------------------------|----------------------------------------------------------------------------------------|------------------------------------------|
| Commit URL (***`repository-name` is optional!***) | `https://github.com/jlord/sheetsee.js/commit/a5c3785ed8d6a35868bc169f07e40e889087fd2e` | `a5c3785` or `jlord/sheetsee.js@a5c3785` |
| SHA (***`repository-name` is required!***) | `a5c3785ed8d6a35868bc169f07e40e889087fd2e` | `a5c3785` |
| `User@SHA` (***Not supported!*** ) | `jlord@a5c3785ed8d6a35868bc169f07e40e889087fd2e` | ***Not supported!*** |
| `Username/Repository@SHA` | `jlord/sheetsee.js@a5c3785ed8d6a35868bc169f07e40e889087fd2e` | `jlord/sheetsee.js@a5c3785` |

## Example

Here is the source code for a minimal example: [example.qmd](example.qmd).
7 changes: 7 additions & 0 deletions _extensions/github/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Github
author: Mickaël Canouil
version: 1.0.0
quarto-required: ">=1.3.450"
contributes:
filters:
- github.lua
138 changes: 138 additions & 0 deletions _extensions/github/github.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
--[[
# MIT License
#
# Copyright (c) Mickaël Canouil
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
]]

local function is_empty(s)
return s == nil or s == ''
end

local github_repository = nil

function get_repository(meta)
local meta_github_repository = nil
if not is_empty(meta['repository-name']) then
meta_github_repository = pandoc.utils.stringify(meta['repository-name'])
end
github_repository = meta_github_repository
return meta
end

function issues(elem)
local user_repo = nil
local issue_number = nil
local type = nil
local short_link = nil

if elem.text:match("^#(%d+)$") then
issue_number = elem.text:match("^#(%d+)$")
user_repo = github_repository
type = "issues"
short_link = "#" .. issue_number
elseif elem.text:match("^([^/]+/[^/#]+)#(%d+)$") then
user_repo, issue_number = elem.text:match("^([^/]+/[^/#]+)#(%d+)$")
type = "issues"
short_link = user_repo .. "#" .. issue_number
elseif elem.text:match("^GH%-(%d+)$") then
issue_number = elem.text:match("^GH%-(%d+)$")
user_repo = github_repository
type = "issues"
short_link = "#" .. issue_number
elseif elem.text:match("^https://github.com/([^/]+/[^/]+)/([^/]+)/(%d+)$") then
user_repo, type, issue_number = elem.text:match("^https://github.com/([^/]+/[^/]+)/([^/]+)/(%d+)$")
if user_repo == github_repository then
short_link = "#" .. issue_number
else
short_link = user_repo .. "#" .. issue_number
end
end

local uri = nil
local text = nil
if not is_empty(short_link) and not is_empty(issue_number) and not is_empty(user_repo) and not is_empty(type) then
if type == "issues" or type == "discussions" or type == "pull" then
uri = "https://github.com/" .. user_repo .. '/' .. type .. '/' .. issue_number
text = pandoc.utils.stringify(short_link)
end
end

return uri, text
end

function commits(elem)
local user_repo = nil
local commit_sha = nil
local type = nil
local short_link = nil

if elem.text:match("^(%w+)$") and elem.text:len() == 40 then
commit_sha = elem.text:match("^(%w+)$")
user_repo = github_repository
type = "commit"
short_link = commit_sha:sub(1, 7)
elseif elem.text:match("^([^/]+/[^/@]+)@(%w+)$") then
user_repo, commit_sha = elem.text:match("^([^/]+/[^/@]+)@(%w+)$")
type = "commit"
short_link = user_repo .. "@" .. commit_sha:sub(1, 7)
elseif elem.text:match("^(%w+)@(%w+)$") then
user_repo, commit_sha = elem.text:match("^(%w+)@(%w+)$")
if commit_sha:len() == 40 then
type = "commit"
short_link = user_repo .. "@" .. commit_sha:sub(1, 7)
end
elseif elem.text:match("^https://github.com/([^/]+/[^/]+)/([^/]+)/(%w+)$") then
user_repo, type, commit_sha = elem.text:match("^https://github.com/([^/]+/[^/]+)/([^/]+)/(%w+)$")
if user_repo == github_repository then
short_link = commit_sha:sub(1, 7)
else
short_link = user_repo .. "@" .. commit_sha:sub(1, 7)
end
end

local uri = nil
local text = nil
if not is_empty(short_link) and not is_empty(commit_sha) and not is_empty(user_repo) and not is_empty(type) then
if type == "commit" and commit_sha:len() == 40 then
uri = "https://github.com/" .. user_repo .. '/' .. type .. '/' .. commit_sha
text = pandoc.utils.stringify(short_link)
end
end

return uri, text
end

function github(elem)
uri, text = issues(elem)
if not is_empty(uri) and not is_empty(text) then
return pandoc.Link(text, uri)
end

uri, text = commits(elem)
if not is_empty(uri) and not is_empty(text) then
return pandoc.Link(text, uri)
end
end

return {
{Meta = get_repository},
{Str = github}
}
78 changes: 78 additions & 0 deletions example.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: "Autolinked references and URLs"
description: |
References to URLs, issues, pull requests, and commits are automatically shortened and converted into links.
page-layout: full
filters:
- github
repository-name: jlord/sheetsee.js
format:
html:
output-file: index
---

Source: [Autolinked references and URLs - GitHub Docs](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls).

## Usage

You can reference URLs, issues, pull requests, and commits in your content.
This Quarto extension automatically shortens and converts GitHub references into links.

```yml
filters:
- github
```
Some references require to define the default repository via `repository-name` YAML key.

```yml
repository-name: jlord/sheetsee.js
```

## Issues and pull requests

+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+
| Reference type | Raw reference | Short link |
+===============================================================================+================================================+================================================+
| | ```txt | |
| Issue, discussion, or pull request URL | https://github.com/jlord/sheetsee.js/issues/26 | https://github.com/jlord/sheetsee.js/issues/26 |
| ***`repository-name` is optional!*** | ``` | |
+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+
| | ```txt | |
| `#` and issue, discussion, or pull request number \ | #26 | #26 |
| ***`repository-name` is required!*** | ``` | |
+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+
| | ```txt | |
| `GH-` and issue, discussion, or pull request number \ | GH-26 | GH-26 |
| ***`repository-name` is required!*** | ``` | |
+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+
| | ```txt | |
| `Username/Repository#` and issue, discussion, or pull request number | jlord/sheetsee.js#26 | jlord/sheetsee.js#26 |
| | ``` | |
+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+
| | ```txt | |
| `Organization_name/Repository#` and issue, discussion, or pull request number | github-linguist/linguist#4039 | github-linguist/linguist#4039 |
| | ``` | |
+-------------------------------------------------------------------------------+------------------------------------------------+------------------------------------------------+

## Commit SHAs

+--------------------------------------+--------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| Reference type | Raw reference | Short link |
+======================================+======================================================================================+======================================================================================+
| | ```txt | |
| Commit URL | https://github.com/jlord/sheetsee.js/commit/a5c3785ed8d6a35868bc169f07e40e889087fd2e | https://github.com/jlord/sheetsee.js/commit/a5c3785ed8d6a35868bc169f07e40e889087fd2e |
| ***`repository-name` is optional!*** | ``` | |
+--------------------------------------+--------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| | ```txt | |
| SHA \ | a5c3785ed8d6a35868bc169f07e40e889087fd2e | a5c3785ed8d6a35868bc169f07e40e889087fd2e |
| ***`repository-name` is required!*** | ``` | |
+--------------------------------------+--------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| | ```txt | |
| `User@SHA` \ | jlord@a5c3785ed8d6a35868bc169f07e40e889087fd2e | ***Not supported!*** |
| ***Not supported!*** | ``` | |
+--------------------------------------+--------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| | ```txt | |
| `Username/Repository@SHA` | jlord/sheetsee.js@a5c3785ed8d6a35868bc169f07e40e889087fd2e | jlord/sheetsee.js@a5c3785ed8d6a35868bc169f07e40e889087fd2e |
| | ``` | |
+--------------------------------------+--------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+

0 comments on commit 188861a

Please sign in to comment.