cescript / MarkdownFormula

Use Excel-like formulas in markdown tables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Markdown Formula

markdown formula is a Visual Studio Code extension which evaluates Excel-like formulas in markdown tables. To make markdown readable with other parsers and to emphazise that the cell value is the output of a formula, link style formatting is used to create a formula. The structure of a markdown formula consist of two parts:

    [VALUE](#FORMULA)

Here, "#FORMULA" is the Excel-like formula which will be evaluated. The hash symbol (#) is used to identify the markdown-formula and it is a replacement for '=' sign in Excel formulas. The purpose of using '#' instead of '=' is to take advantage of the URI fragments and create valid URL address from the given formulas. The "VALUE" is the result of the "#FORMULA" and automatically generated by this extension. All the calculations are fulfilled via the popular open-source library HyperFormula.

Using the Excel-like naming convention, table columns are addressed with letters (A,B,...) and the table rows are addressed with numbers (1,2,..).

markdown formula parses all the tables in the current document and seperates them as sheets. If a comment line ('<!-- NAME -->') exist just before the table header, it is assigned as the sheetname for the table. If a comment line does not exist, the sheet name is automatically generated as "Sheet#N" where the #N is the zero based order of the table in the document.

Basic Example

In this basic example, we have a table which consist of five rows and three columns. The last column of the first two rows (namely C1 and C2) are used to construct the (C3:C5) rows.

name formula values
three - 3
eight - 8
summation #SUM(C1:C2) 11
multiplication #C1*C2 24
average #AVERAGE(C1:C2) 5.5

Using Cells From Other Sheets

In this example, we will use the cells of the previous table in our current table.

name formula values1 values2
six and one - 6 1
summation from table1 #table1!C3 4 11
summation and average #SUM(C1:D2),#AVERAGE(C1:D2) 22 5.5
count larger than 3 #COUNTIF(C1:C3,">3"),#COUNTIF(D1:D3,">3") 3 2

Extension Settings

markdown formula has some customization options under the VS Code's settings panel.

  • precisionRounding: Rounding precision for floating point numbers can be set.
  • includeTableHeaderInCellNumaration: If set to true, the table header is included as the first row in cell enumaration.
  • calculateOnSave: If set to true, the formulas on the tables will be recalculated and the tables will be updated before writing the file to the disk.

How to Use

You have three alternatives to install this extension.

  1. Download it from VS Code Extension Marketplace.
  2. Download the prebuilt version under the releases tab
  3. Build it from the source

After installing the extension;

  • Open a document which contains markdown tables and formulas
  • Save the document to automatically calculate the formulas or Press Ctrl+Shift+P to run a command, write "Calculate all formulas" and press Enter to manually update the formulas
  • All the formula cells in your document should be updated with the calculated values

About

Use Excel-like formulas in markdown tables

License:GNU General Public License v3.0


Languages

Language:TypeScript 100.0%