Created
December 23, 2017 03:21
-
-
Save skyzh/bb49bf539fcb872c86997fc788d26d6e to your computer and use it in GitHub Desktop.
Export Anki cards to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
How to use? | |
Install Node.js and run 'npm init', than install the dependency 'lodash'. | |
Install the Anki addon from 'https://ankiweb.net/shared/info/1788670778', and export your deck to JSON. | |
Run 'node index.js', and there will be a generated 'index.html'. | |
*/ | |
const _ = require('lodash'); | |
const fs = require('fs'); | |
const wrap_html = (html) => ` | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>Anki Export</title> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<style> | |
.anki-card { | |
page-break-inside: avoid; | |
font-family: "Noto Serif", "Noto Serif CJK SC Medium"; | |
} | |
</style> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> | |
</head> | |
<body> | |
${html} | |
</body> | |
</html>`; | |
const wrap_card_column = (html) => ` | |
<div class="card-columns"> | |
${html} | |
</div>`; | |
const wrap_card = (question, answer) => ` | |
<div class="card anki-card"> | |
<div class="card-body py-1"> | |
<p class="card-text my-1">${question}</p> | |
<hr class="my-1"> | |
<p class="card-text my-1">${answer}</p> | |
</div> | |
</div> | |
`; | |
const data = require('./1_Translation.json'); //Change it to your JSON file | |
let html = _.chain(data.notes).map(card => wrap_card(card.fields[0], card.fields[1])).join(''); | |
fs.writeFile('index.html', wrap_html(wrap_card_column(html)), (err) => { | |
if (err) throw err; | |
console.log('The file has been saved!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment