Skip to content

Commit

Permalink
Begun AgregoreWeb#8 ,added script for orgmode but hook does not trigger
Browse files Browse the repository at this point in the history
Implemented Orgmode Rendering

Cleaned up for patch
  • Loading branch information
telamon committed Jul 26, 2024
1 parent 7cefbc5 commit d4d6cd4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ bundle-json.js
bundle-markdown.js
bundle-ssb.js
bundle-reader.js
bundle-orgmode.js
6 changes: 4 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ const TYPE_MAP = {
// TODO: Hooks for activitystream rendering?
'application/activity+json': 'json',
'application/ld+json': 'json',
'application/ssb+json': 'ssb'
'application/ssb+json': 'ssb',
'text/x-org': 'orgmode'
}

const SCRIPT_MAP = {
markdown: scriptURL('markdown'),
gemini: scriptURL('gemini'),
json: scriptURL('json'),
ssb: scriptURL('ssb')
ssb: scriptURL('ssb'),
orgmode: scriptURL('orgmode')
}

const code = `
Expand Down
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bundle-markdown.js",
"bundle-json.js",
"bundle-ssb.js",
"bundle-reader.js"
"bundle-reader.js",
"bundle-orgmode.js"
]
}
27 changes: 27 additions & 0 deletions orgmode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* global location */
import renderPage from './template.js'
import { unified } from 'unified'
import parse from 'uniorg-parse'
import uniorg2rehype from 'uniorg-rehype'
import stringify from 'rehype-stringify'

export async function renderOrg (orgText) {
const processor = unified()
.use(parse)
.use(uniorg2rehype)
.use(stringify)

const { value: html } = await processor.process(orgText)

const { pathname } = location
const filename = pathname.substring(pathname.lastIndexOf('/') + 1)

// extract first heading as page title, fallback onto filename
const pageTitle = html.match(/<h\d>([^<]+)<\/h\d>/)?.[1] || filename

renderPage(html, pageTitle)
}

const text = document.querySelector('pre').innerText
renderOrg(text)
.catch(err => console.error('Rendering orgmode failed:', err))
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build-gemini": "browserify ./gemini.js > bundle-gemini.js",
"build-ssb": "browserify ./ssb.js > bundle-ssb.js",
"build-reader": "browserify ./reader.js > bundle-reader.js",
"build": "npm run build-markdown && npm run build-json && npm run build-gemini && npm run build-ssb && npm run build-reader"
"build-org": "esbuild --bundle orgmode.js --outfile=bundle-orgmode.js",
"build": "npm run build-markdown && npm run build-json && npm run build-gemini && npm run build-ssb && npm run build-reader && npm run build-org"
},
"repository": {
"type": "git",
Expand All @@ -25,6 +26,7 @@
"homepage": "https://github.com/RangerMauve/extension-agregore-renderer#readme",
"devDependencies": {
"browserify": "^17.0.0",
"esbuild": "^0.23.0",
"standard": "^17.0.0"
},
"dependencies": {
Expand All @@ -33,10 +35,14 @@
"gemini-to-html": "^2.2.0",
"html-to-text": "^8.2.0",
"marked": "^4.0.16",
"rehype-stringify": "^10.0.0",
"ssb-fetch": "^1.5.2",
"ssb-markdown": "^6.0.7",
"ssb-ref": "^2.16.0",
"ssb-uri2": "^1.8.1"
"ssb-uri2": "^1.8.1",
"unified": "^11.0.5",
"uniorg-parse": "^3.0.1",
"uniorg-rehype": "^1.2.0"
},
"standard": {
"ignore": [
Expand Down

0 comments on commit d4d6cd4

Please sign in to comment.