-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): added documentation for using a CDN
- Loading branch information
1 parent
09d1466
commit bef99a8
Showing
6 changed files
with
101 additions
and
52 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<script type="module"> | ||
import {WorkerLinter} from "https://unpkg.com/[email protected]/dist/harper.js" | ||
|
||
let linter = new WorkerLinter(); | ||
|
||
async function onInput(e) { | ||
let lints = await linter.lint(e.target.value); | ||
|
||
let list = document.getElementById("errorlist"); | ||
// Clear previous results | ||
list.innerHTML = ''; | ||
|
||
|
||
for (let lint of lints) { | ||
let item = document.createElement("LI"); | ||
var text = document.createTextNode(lint.message()); | ||
item.appendChild(text); | ||
list.appendChild(item); | ||
} | ||
} | ||
|
||
let inputField = document.getElementById("maininput"); | ||
inputField.addEventListener("input", onInput); | ||
onInput({target: inputField}) | ||
</script> | ||
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> | ||
</head> | ||
|
||
<body> | ||
<h1>Demo</h1> | ||
|
||
<p> | ||
This page is a simple example of using <code>harper.js</code> on a plain HTML page with a CDN. | ||
It isn't pretty, but it demonstrates the fundamentals of using Harper. | ||
Start typing in the text box below to start getting suggestions right in your browser. | ||
</p> | ||
|
||
<textarea id="maininput">This is an test</textarea> | ||
|
||
<h2>Errors</h2> | ||
|
||
<ul id="errorlist"> | ||
Loading | ||
</ul> | ||
|
||
</body> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<script type="module"> | ||
// We can import `harper.js` using native ECMAScript syntax. | ||
import { WorkerLinter } from 'https://unpkg.com/[email protected]/dist/harper.js'; | ||
|
||
// Since we are working the browser, we can use either `WorkerLinter`, which doesn't block the event loop, or `LocalLinter`, which does. | ||
let linter = new WorkerLinter(); | ||
|
||
// Every time the `<textarea/>` received an input, we process it and update our list. | ||
async function onInput(e) { | ||
let lints = await linter.lint(e.target.value); | ||
|
||
let list = document.getElementById('errorlist'); | ||
// Clear previous results | ||
list.innerHTML = ''; | ||
|
||
for (let lint of lints) { | ||
let item = document.createElement('LI'); | ||
var text = document.createTextNode(lint.message()); | ||
item.appendChild(text); | ||
list.appendChild(item); | ||
} | ||
} | ||
|
||
let inputField = document.getElementById('maininput'); | ||
inputField.addEventListener('input', onInput); | ||
onInput({ target: inputField }); | ||
</script> | ||
|
||
<!--Make the page look good using SimpleCSS--> | ||
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css" /> | ||
</head> | ||
|
||
<body> | ||
<h1>Demo</h1> | ||
|
||
<p> | ||
This page is a simple example of using <code>harper.js</code> on a plain HTML page with a CDN. | ||
It isn't pretty, but it demonstrates the fundamentals of using Harper. Start typing in the | ||
text box below to start getting suggestions right in your browser. | ||
</p> | ||
|
||
<!--This is an intentional mistake to highlight the technology.--> | ||
<textarea id="maininput">This is an test</textarea> | ||
|
||
<h2>Errors</h2> | ||
|
||
<ul id="errorlist"> | ||
Loading... | ||
</ul> | ||
</body> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Using a CDN | ||
--- | ||
|
||
You can consume Harper from the [unpkg](https://unpkg.com/) CDN using native ECMAScript module syntax which is supported by all modern browsers. | ||
|
||
[A simple example is provided below.](./CDN/example) | ||
|
||
@code(../../../../../../harper.js/examples/raw-web/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pageHtml from '../../../../../../../harper.js/examples/raw-web/index.html?raw'; | ||
|
||
export async function GET() { | ||
return new Response(pageHtml, { | ||
headers: { | ||
['Content-Type']: 'text/html' | ||
} | ||
}); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/web/src/routes/docs/harperjs/introduction/+page.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Introduction to harper.js | ||
--- | ||
|
||
## The Mission | ||
|
||
If you're a developer, odds are that you are using JavaScript or TypeScript on a daily basis. | ||
Your project probably has a least a little bit of either. | ||
|
||
Furthermore, a plurality of focused authorship happens inside a web browser or [Electron-based app](https://www.electronjs.org/). | ||
Given this, we want to create an environment where it is as easy as possible to integrate fantastic grammar checking into web applications. | ||
|
||
## What is `harper.js`? | ||
|
||
`harper.js` is an ECMAScript module designed to easy to import into any project. | ||
On the inside, it uses a copy of Harper compiled to [WebAssembly](https://webassembly.org/). |
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
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