This project aims to automate the process of creating Anki cards. To create cards, in batch, you can write a simple LaTeX or Markdown document which is then transformed into markdown and csv file. The latter is used to be imported into Anki. The former is simplified LaTeX document for reading without compiled LaTeX document. You can easily create a LaTeX document using txtemplate.
Command line interface transforms LaTeX document into markdown and csv files or simply markdown to csv. The goal of this program is making process of creating Anki cards easier and faster by writing Anki card in a single file which can be easily modified and searched for changes and automatically calling Anki for import. Windows users need to set Anki environmental variable for auto importing.
- Node.js
- TypeScript
- commander.js
To get started you need installed Node.js LTS 14.x or later alongside other tools.
- Node.js LTS 14.x or later
- TypeScript
- Install Node.js
- Clone the repo
git clone https://github.com/janmerhar/txmanipulator
- Install NPM packages
npm install
- Install TypeScript
npm install typescript -g
- Run TypeScript compiler
npm run build
Script is located in bin
folder. You can run it with ts-node
. Note, if you want to run JavaScript script, you fill find compiled executable in dist/bin
folder.
To use CLI you need to install package from NPM using npm install txmanipulator -g
. Afterwards you can run the CLI using manipulator
command.
Usage: manipulator [options]
Options:
-i, --input <string> Name of file that will be imported
-tof, --type-of-file <number> 1 => MD file, 2 => CSV file, 3 => MD and CSV
file (default: "3")
-at, --anki-tag <string> Input tag field value for imported document:
eg. OMA-13
-f, --file-name <string> Name of the output file
-r, --run <number> 1 => runs manipulated data in program, 0 =>
doesn't run anything (default: "1")
-h, --help display help for command
import { MDManipulator } from "txmanipulator"
const md = new MDManipulator(
"name_of_input_file.md",
"name_of_output_file.csv",
"name_of_anki_tag",
"run_option: int"
)
md
// Detecting and encapsulating images in <img> tags
.imageDetection()
// Detecting blocks of code and translating them into HTML
.codeDetection()
// Creating basic data for writing to csv file
.fillCsvData2()
// Customization for specific type of anki cards' titles
.CSVstyleAllTitles()
// Cosmetic improvement for every title of anki cards
.titleAnswerReplaceSpecial()
// Translating \n line breaks to HTML tag <br>
.CSVLineBreaksToHTML()
// Finally writing computed anki cards to .csv file
md.csvWriteToFile()
import { LaTeXManipulator } from "txmanipulator"
const tex = new LaTeXManipulator(
"name_of_input_file.md",
"name_of_output_file.csv",
"name_of_anki_tag",
"run_option: int"
)
tex
// Remove \n end lines
.removeEndlines()
// Remove \t tabs
.removeTabs()
// Remove \section LaTeX tags
.removeSections()
// Remove remaining LaTeX tags
.removeLaTeX()
// Remove double \n\n end lines
.removeDoubleEmptyLines()
// Remove LaTeX commented lines that start with %
.removeLaTeXComments()
// Finally writing computed Markdown file to .md file
tex.writeToFile()
To contribute to this project follow these steps:
- Fork the repository
- Create feature branch (
git checkout -b feature/NewFeature
) - Commit changes (
git commit -m 'Add some changes'
) - Push to the branch (
git push origin feature/NewFeature
) - Open a pull request