Skip to content

Commit

Permalink
Merge pull request #6 from orgzly-revived/174-id-links-for-notebooks-…
Browse files Browse the repository at this point in the history
…dont-work

Add support for parsing OrgProperties from any string
  • Loading branch information
amberin authored Dec 27, 2024
2 parents c797a9f + 59c26d0 commit 438b746
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/com/orgzly/org/OrgProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;

/**
* a
Expand Down Expand Up @@ -152,4 +151,23 @@ public boolean isEmpty() {
public boolean containsKey(String name) {
return values.containsKey(name);
}

public static OrgProperties fromString(String preface) {
OrgProperties properties = new OrgProperties();
boolean inProperties = false;
for (String line : preface.split("\n")) {
String lineTrimmed = line.trim();
if (!inProperties && ":PROPERTIES:".equals(lineTrimmed)) {
inProperties = true;
} else if (inProperties && ":END:".equals(lineTrimmed)) {
inProperties = false;
} else if (inProperties) {
Matcher propertyMatcher = OrgPatterns.PROPERTY.matcher(lineTrimmed);
if (propertyMatcher.find()) {
properties.put(propertyMatcher.group(1), propertyMatcher.group(2).trim());
}
}
}
return properties;
}
}

0 comments on commit 438b746

Please sign in to comment.