Skip to content

Preserve blanks and uses #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ assert.deepEqual(
{ content: [ 'A' ] })
```

Converts term uses to strings:
Passes term uses through:

```javascript
assert.deepEqual(
resolve(
{ content: [ { use: 'A' } ] },
{ }),
{ content: [ 'A' ] })
{ content: [ { use: 'A' } ] })
```

Passes definitions through:
Expand All @@ -34,14 +34,14 @@ assert.deepEqual(
{ content: [ { definition: 'A' } ] })
```

Replaces blanks with provided values, or a blank when none are provided:
Provides blank values:

```javascript
assert.deepEqual(
resolve(
{ content: [ { blank: 'A' } ] },
{ A: '1' }),
{ content: [ '1' ] })
{ content: [ { blank: 'A', value: '1' } ] })

assert.deepEqual(
resolve(
Expand Down Expand Up @@ -102,19 +102,6 @@ assert.deepEqual(

```

Concatenates strings and contiguous objects that are resolved to strings:

```javascript
assert.deepEqual(
resolve({ content: [ 'A', { use: 'B' } ] }, { }).content,
[ 'AB' ])

assert.deepEqual(
resolve({ content: [ { use: 'A' }, 'B' ] }, { }).content,
[ 'AB' ])

```

Preserves conspicuous formatting flags:

```javascript
Expand Down
6 changes: 3 additions & 3 deletions element.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(element, values, numbering, headings) {
if (predicate.text(element)) {
return element }
else if (predicate.use(element)) {
return element.use }
return element }
else if (predicate.child(element)) {
element.numbering = numbering.numbering
element.form = resolve(
Expand Down Expand Up @@ -44,9 +44,9 @@ module.exports = function(element, values, numbering, headings) {
var value = element.blank
// Filled
if (values.hasOwnProperty(value)) {
return values[value] }
return { blank: value, value: values[value] } }
// Empty
else {
return {blank: value} } }
return { blank: value } } }
else {
throw new Error('Invalid content: ' + JSON.stringify(element)) } }
16 changes: 0 additions & 16 deletions form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var resolveElement = require('./element')

module.exports = function(form, values, numberings, headings) {
form.content = form.content
// resolve content
.map(function(element, index) {
var numbering = (
( numberings &&
Expand All @@ -11,19 +10,4 @@ module.exports = function(form, values, numberings, headings) {
numberings.content[index] : null )
return resolveElement(element, values, numbering, headings) })

// Concatenate contiguous strings.
.reduce(
function(content, element, index) {
var count = content.length
var last = content[count - 1]
if (
index > 0 &&
typeof element === 'string' &&
typeof last === 'string')
{ content[count - 1] = last + element }
else {
content.push(element) }
return content },
[])

return form }