Skip to content

Commit

Permalink
Merge pull request #578 from 200ok-ch/fix/parser-does-not-swallow-pro…
Browse files Browse the repository at this point in the history
…perty-values

fix: Parser does not swallow property values
  • Loading branch information
munen authored Nov 20, 2020
2 parents 43baddc + 5855ffa commit 8bf0860
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions changelog.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All user visible changes to organice will be documented in this file.

When there are updates to the changelog, you will be notified and see a 'gift' icon appear on the top right corner.

* [2020-11-20 Fri]
** Fixed
- organice understands =:PROPERTIES:= drawers and smartly parses the values in case one of the values is a timestamp.
- However, parsing all the values and saving the parsed result in any case will lead to wrong results. Most values of properties are just plain text and non-interactive things in Org mode.
- For example, a value like =something_with_underscores= would have been treated as 'underlined text' which doesn't make sense for a property drawer. When saving the value back, organice would have squashed the underlines.
- Now, the values are used and preserved as they are. Timestamps still work, of course.
- Relevant PR: https://github.com/200ok-ch/organice/pull/578
* [2020-11-15 Sun]
** Fixed
- When repeating a task, an active date timestamp was logged instead of an inactive datetime timestamp.
Expand Down
8 changes: 7 additions & 1 deletion src/components/OrgFile/OrgFile.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ${text}`;

describe('Parsing and exporting should not alter the original file', () => {
test("Parsing and exporting shouldn't alter the original file", () => {
const testOrgFile = readFixture('indented_list');
const testOrgFile = readFixture('all_the_features');
const exportedFile = parseAndExportOrgFile(testOrgFile);

// Should have the same amount of lines. Safeguard for the next
Expand Down Expand Up @@ -171,6 +171,12 @@ ${text}`;
expect(exportedFile).toEqual(testOrgFile);
});

test('Parse a header with PROPERTIES', () => {
const testOrgFile = '* Header\n :PROPERTIES:\n :CUSTOM_ID: link_to_me\n :END:\n';
const exportedFile = parseAndExportOrgFile(testOrgFile);
expect(exportedFile).toEqual(testOrgFile);
});

test('Parse basic file with description', () => {
const testOrgFile = readFixture('bold_text');
const exportedFile = parseAndExportOrgFile(testOrgFile);
Expand Down
9 changes: 8 additions & 1 deletion src/lib/parse_org.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,14 @@ const parsePropertyList = (rawText) => {
return null;
}

const value = !!match[2] ? parseMarkupAndCookies(match[2]) : null;
// Parse the properties value even though most values would
// not need parsing. Only timestamps are interactive, the rest
// will be saved as plain text.
let value = !!match[2] ? parseMarkupAndCookies(match[2]) : null;

if (value && value[0].type !== 'timestamp') {
value = [{ contents: match[2], type: 'text' }];
}

return {
property: match[1],
Expand Down
5 changes: 4 additions & 1 deletion test_helpers/fixtures/all_the_features.org
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

# Complex TODO with priority, active timestamp, link to an email and a tag
**** TODO [#B] <2019-05-02 Thu> Some Person [[mu4e:msgid:CAN6MX5o-i9koRnBXGOFQ-wLUhp82mGCwFSxo0b2i0+TROYNZkg@mail.gmail.com][Re: HÖCHENSCHWAND 05.Februar 2019]] :200ok:

*** Header with =CUSTOM_ID= property
:PROPERTIES:
:CUSTOM_ID: link_to_me
:END:
*** Planning items

**** TODO I am scheduled
Expand Down

0 comments on commit 8bf0860

Please sign in to comment.