Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
Add html to markdown converter
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 28, 2023
1 parent db13e74 commit 1bafc14
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
dist/
node_modules/
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"markdownlint.config": {
"no-inline-html": {
"allowed_elements": ["img", "u", "br"]
},
"no-empty-links": false,
"no-hard-tabs": false,
"single-h1": false
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ cmake --install build
Or you should try `./build.sh` to help you do this.

Then you will get all test file on `dist/`.

## Migrate Description from HTML to Markdown

For the first time, you should install nodejs and run `npm install` to install dependencies.

Then you can run `node html2md.ts <html-file>` to convert HTML to Markdown.
11 changes: 11 additions & 0 deletions html2md.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// For Node.js
var TurndownService = require("turndown");

var htmlPath = process.argv[2];
var html = require("fs").readFileSync(htmlPath, "utf8");

var turndownService = new TurndownService();
var markdown = turndownService.turndown(html);

var markdownPath = htmlPath.replace(/\.html$/, ".raw.md");
require("fs").writeFileSync(markdownPath, markdown);
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"turndown": "^7.1.2"
},
"devDependencies": {
"@types/node": "^20.8.9"
}
}
43 changes: 43 additions & 0 deletions packages/icpc/two-sum/description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="elfjS" data-track-load="description_content">
<p>Given an array of integers <code>nums</code>&nbsp;and an integer <code>target</code>, return <em>indices of the
two numbers such that they add up to <code>target</code></em>.</p>

<p>You may assume that each input would have <strong><em>exactly</em> one solution</strong>, and you may not use the
<em>same</em> element twice.</p>

<p>You can return the answer in any order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre><strong>Input:</strong> nums = [2,7,11,15], target = 9
<strong>Output:</strong> [0,1]
<strong>Explanation:</strong> Because nums[0] + nums[1] == 9, we return [0, 1].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre><strong>Input:</strong> nums = [3,2,4], target = 6
<strong>Output:</strong> [1,2]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre><strong>Input:</strong> nums = [3,3], target = 6
<strong>Output:</strong> [0,1]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= target &lt;= 10<sup>9</sup></code></li>
<li><strong>Only one valid answer exists.</strong></li>
</ul>

<p>&nbsp;</p>
<strong>Follow-up:&nbsp;</strong>Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code>
<font face="monospace">&nbsp;</font>time complexity?
</div>
32 changes: 32 additions & 0 deletions packages/icpc/two-sum/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# [Two Sum](https://leetcode.com/problems/two-sum/)

Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_.

You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice.

You can return the answer in any order.

**Example 1:**

**Input:** nums = \[2,7,11,15\], target = 9 <br/>
**Output:** \[0,1\] <br/>
**Explanation:** Because nums\[0\] + nums\[1\] == 9, we return \[0, 1\].

**Example 2:**

**Input:** nums = \[3,2,4\], target = 6 <br/>
**Output:** \[1,2\]

**Example 3:**

**Input:** nums = \[3,3\], target = 6 <br/>
**Output:** \[0,1\]

**Constraints:**

* `2 <= nums.length <= 104`
* `-109 <= nums[i] <= 109`
* `-109 <= target <= 109`
* **Only one valid answer exists.**

**Follow-up:** Can you come up with an algorithm that is less than `O(n2)` time complexity?

0 comments on commit 1bafc14

Please sign in to comment.