Jump to content

DevDoc with Markdown View?


Recommended Posts

Hi, I have zero experience creating workflow but do have programming experience (C & C++). I was reversing a way to get devdoc indexing and getting database (DB). The motivation behind it is that, I dont own dash (yearly subscription) and looking for a free alternative that run within Alfred with markdown preview . It is similar to nvim-devdoc, which gets the DB using curl and converts html to markdown.

 

 

## Curl Request:

// JSON NOOB HERE


const find 	= `c`;
const indexUrl 	= `/index.json`
const dbUrl 	= `/db.json`
const devdocUrl = `https://documents.devdocs.io/`;

// Get index
const rawHTML = app.doShellScript(`curl -sL '${devdocUrl}${find}${indexUrl}'`);

// Get db
const rawHTMLL = app.doShellScript(`curl -sL '${devdocUrl}${find}${dbUrl}'`);

 

## HTML to Markdown

Taken from nvim-devdoc (transpiler.lua)

local normalize_html = function(str)
  local symbol_map = {
    ["&lt;"] = "<",
    ["&gt;"] = ">",
    ["&amp;"] = "&",
    ["&quot;"] = '"',
    ["&apos;"] = "'",
    ["&nbsp;"] = " ",
    ["&copy;"] = "©",
    ["&ndash;"] = "–",
  }

  for key, value in pairs(symbol_map) do
    str = str:gsub(key, value)
  end

  return str
end

local tag_mappings = {
  h1 = { left = "# ", right = "\n\n" },
  h2 = { left = "## ", right = "\n\n" },
  h3 = { left = "### ", right = "\n\n" },
  h4 = { left = "#### ", right = "\n\n" },
  h5 = { left = "##### ", right = "\n\n" },
  h6 = { left = "###### ", right = "\n\n" },
  span = {},
  nav = {},
  header = {},
  div = { left = "\n", right = "\n" },
  section = { right = "\n" },
  p = { right = "\n\n" },
  ul = { right = "\n" },
  ol = { right = "\n" },
  dl = { right = "\n" },
  dt = { right = "\n" },
  figure = { right = "\n" },
  dd = { left = ": " },
  pre = { left = "\n```\n", right = "\n```\n" },
  code = { left = "`", right = "`" },
  samp = { left = "`", right = "`" },
  var = { left = "`", right = "`" },
  kbd = { left = "`", right = "`" },
  mark = { left = "`", right = "`" },
  tt = { left = "`", right = "`" },
  b = { left = "`", right = "`" },
  strong = { left = "**", right = "**" },
  i = { left = "_", right = "_" },
  s = { left = "~~", right = "~~" },
  em = { left = "_", right = "_" },
  small = { left = "_", right = "_" },
  sup = { left = "^", right = "^" },
  blockquote = { left = "> " },
  summary = { left = "<", right = ">" },

  -- TODO: Handle these correctly
  math = { left = "```math\n", right = "\n```" },
  annotation = { left = "[", right = "]" },
  semantics = {},
  mspace = { left = " " },
  msup = { right = "^" },
  mfrac = { right = "/" },
  mrow = {},
  mo = {},
  mn = {},
  mi = {},

  br = { right = "\n" },
  hr = { right = "---\n\n" },
}

local inline_tags = {
  "span",
  "a",
  "strong",
  "em",
  "abbr",
  "code",
  "tt",
  "i",
  "s",
  "b",
  "sub",
  "sup",
  "mark",
  "small",
  "var",
  "kbd",
}

local skipable_tags = {
  "input",
  "use",
  "svg",
  "button",

  -- exceptions, (parent) table -> child
  "tr",
  "td",
  "th",
  "thead",
  "tbody",
}

local monospace_tags = {
  "code",
  "tt",
  "samp",
  "kbd",
}

 

Would like the forum advice turning this into a plugin!

Edited by RealNerd
Grammar
Link to comment
On 4/22/2024 at 6:48 PM, protonymus said:

I think the difficult part is converting HTML to the Markdown flavor compatible with Alfred. For a first test, I tried using pandoc, but it failed. 

 

I played with this yesterday and the results were rather disappointing. The most limiting factor is the lack of support for markdown tables in Alfred's Text View. Syntax highlighting would also make a big difference. There were a lot of inconsistencies with pandoc, mostly around the broken tables. Html2md, a Go cli tool, produced slightly better and more consistent results, which are still messy when thrown at the Text View as it is now. 

 

Here's another alternative I found without markdown view that holds up well: alfred-devdocs.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...