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

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 15, 2014
0 parents commit 5383ac9
Show file tree
Hide file tree
Showing 10 changed files with 2,093 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
coverage
144 changes: 144 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireMultipleVarDecl": true,
"requireBlocksOnNewline": true,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowDanglingUnderscores": true,
"requireSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowLeftStickedOperators": [
"?",
"+",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireRightStickedOperators": ["!"],
"disallowRightStickedOperators": [
"?",
"+",
"/",
"*",
":",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireLeftStickedOperators": [","],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": ["with"],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"maximumLineLength": 78,
"requireCapitalizedConstructors": true,
"safeContextKeyword": "self",
"requireDotNotation": true,
"disallowYodaConditions": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
.travis.yml
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: "node_js"
before_install:
- "npm update -g npm"
script: "npm run-script test-travis"
node_js:
- "0.10"
- "0.11"
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2014 Titus Wormer <tituswormer@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
143 changes: 143 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# retext-range [![Build Status](https://travis-ci.org/wooorm/retext-range.svg?branch=master)](https://travis-ci.org/wooorm/retext-range) [![Coverage Status](https://img.shields.io/coveralls/wooorm/retext-range.svg)](https://coveralls.io/r/wooorm/retext-range?branch=master)

[![browser support](https://ci.testling.com/wooorm/retext-range.png) ](https://ci.testling.com/wooorm/retext-range)

See [Browser Support](#browser-support) for more information (a.k.a. don’t worry about those grey icons above).

---

Ranges—similar to DOM’s [Range](http://dom.spec.whatwg.org/#introduction-to-dom-ranges)—for [retext](https://github.com/wooorm/retext "Retext"): A Range object represents a sequence of content within a TextOM tree. Each range has a start and an end (two “boundary points”—each in turn a node and an offset). In other words, a range represents a piece of content within a TextOM tree between two points.

## Installation

NPM:
```sh
$ npm install retext-range
```

Component.js:
```sh
$ component install wooorm/retext-range
```

## Usage

```js
var Retext = require('retext'),
retextRange = require('retext-range');

var root = new Retext()
.use(retextRange)
.parse(
'Some simple English words in a sentence. And some ' +
'more words in another sentence.'
);

/* The tree now looks as follows:
*
* RootNode:
* └─ ParagraphNode:
* ├─ SentenceNode:
* │ ├─ WordNode: "Some"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "simple"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "English"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "words"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "in"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "a"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "sentence"
* │ └─ PunctuationNode: "."
* ├─ WhiteSpaceNode: " "
* └─ SentenceNode:
* ├─ WordNode: "And"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "some"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "more"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "words"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "in"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "another"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "sentence"
* └─ PunctuationNode: "."
*/

var range = new root.TextOM.Range(),
firstSentenceNode = root.head.head,
lastSentenceNode = root.head.tail,
start = firstSentenceNode[11], // WhiteSpaceNode: " ", after "a"
end = lastSentenceNode[10]; // WordNode: "another"

// Select some content:
range.setStart(start);
range.setEnd(end, 1); // "a|nother"

// Remove the content covered by the range:
range.removeContent();

/* The tree now looks as follows:
*
* RootNode:
* └─ ParagraphNode:
* ├─ SentenceNode:
* │ ├─ WordNode: "Some"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "simple"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "English"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "words"
* │ ├─ WhiteSpaceNode: " "
* │ ├─ WordNode: "in"
* │ ├─ WhiteSpaceNode: " "
* │ └─ WordNode: "a"
* └─ SentenceNode:
* ├─ WordNode: "nother"
* ├─ WhiteSpaceNode: " "
* ├─ WordNode: "sentence"
* └─ PunctuationNode: "."
*/
```

Note that the sentences are **not** joined together, retext-range is agnostic about content (meaning), and just looks at the nodes the user selects. The white space between the two sentences is however removed, as it was completely covered by the range.

## API

#### TextOM.Range()
Constructor. Creates a new Range (an object allowing for cross-tree manipulation).

##### TextOM\.Range#setStart(node, offset?)
Set the start container and offset of a range.

- node (`Node`): The node to start the range at or in;
- offset (Non-negative integer [`Number`], `null`, or `Infinity`): Point to end at, defaults to `null`.

##### TextOM\.Range#setEnd(node, offset?)
Set the end container and offset of a range.

- node (`Node`): The node to end the range at or in;
- offset (Non-negative integer [`Number`], `null`, or `Infinity`): Point to end at, defaults to `Infinity`.

##### TextOM\.Range#toString()
Return the result of calling `toString` on each completely covered node inside `range`, sub-stringing partially covered nodes when necessary.

##### TextOM\.Range#removeContent()
Removes each completely covered node inside `range`, splitting partially covered nodes when necessary. Returns an array containing the removed nodes.

##### TextOM\.Range#getContent()
Returns an array containing each completely covered node inside `range`, ignores partially covered Text nodes (Word, WhiteSpace, and Punctuation).

## Browser Support
Pretty much every browser (available through BrowserStack) runs all retext-content unit tests.

## License

MIT
14 changes: 14 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "retext-range",
"repository": "wooorm/retext-range",
"description": "Sequences of content within a TextOM tree between two points",
"version": "0.0.1",
"keywords": [
"retext",
"range"
],
"scripts" : [
"index.js"
],
"license": "MIT"
}
Loading

0 comments on commit 5383ac9

Please sign in to comment.