Skip to content

Commit

Permalink
First Commit: Single directional sync from nbx format to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
absozero committed Jul 23, 2024
1 parent 2036fd4 commit 59bfd3a
Show file tree
Hide file tree
Showing 5 changed files with 1,115 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
87 changes: 87 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>HTML 5 Boilerplate</title>
</head>
<body>
<script>
var markdown;
// Helper function to convert the json object input as a parameter into markdown text
function convert(JSONObj) {
markdown = "# " + JSONObj.title.replaceAll("\n", " - ") + "\n\n";
for (var i = 0; i < JSONObj.lists.length; i++) {
console.log(JSONObj.lists[i]);
markdown +=
"## " + JSONObj.lists[i].title.replaceAll("\n", " - ") + "\n\n";
for (var j = 0; j < JSONObj.lists[i].notes.length; j++) {
console.log(JSONObj.lists[i].notes[j].text);
markdown +=
"- " +
JSONObj.lists[i].notes[j].text.replaceAll("\n", " - ") +
"\n";
}
markdown += "\n";
}
return markdown;
}

function downloadBlob(blob, name = "output.md") {
// Convert your blob into a Blob URL (a special url that points to an object in the browser's memory)
const blobUrl = URL.createObjectURL(blob);

// Create a link element
const link = document.createElement("a");

// Set link's href to point to the Blob URL
link.href = blobUrl;
link.download = name;

// Append link to the body
document.body.appendChild(link);

// Dispatch click event on the link
// This is necessary as link.click() does not work on the latest firefox
link.dispatchEvent(
new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
}),
);

// Remove link from body
document.body.removeChild(link);
}

window.onload = function () {
document
.getElementById("fileInput")
.addEventListener("change", function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var jsonObj = JSON.parse(e.target.result);

markdown = convert(jsonObj);
document.getElementById("output").innerText = markdown;

console.log(markdown);
};
reader.readAsText(file);
});
};
function dlmd() {
let jsonBlob = new Blob([markdown]);
downloadBlob(jsonBlob, "output.md");
}
</script>
<!--Creates a button that takes any text file as input-->
<input type="file" id="fileInput" />
<button onclick="convert()">Convert</button>
<button id="demo" onclick="dlmd()">download.</button>
<div id="output"></div>
</body>
</html>
Loading

0 comments on commit 59bfd3a

Please sign in to comment.