X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fcore%2Fdocument%2Ftext%2FHyperlink.java;h=508003c5c0a7993d5882d0b14c2964a8157134b1;hp=5e6884ce9691aff2c6d47308e4779a1e26399142;hb=168cf05300cec2bb4c0607711b752609976b2901;hpb=e37d8d2a8afaf35a27bc65d8d700eeea5ed5bd46 diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java b/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java index 5e6884c..508003c 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java @@ -1,6 +1,5 @@ package eu.svjatoslav.sixth.core.document.text; -import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; import eu.svjatoslav.commons.string.tokenizer.Terminator; import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; @@ -10,32 +9,36 @@ import static eu.svjatoslav.sixth.core.document.Helper.TG_HYPERLINK; public class Hyperlink implements FormattedTextElement { public static final Terminator orgTerminator = - new Terminator(PRESERVE, "\\[\\[.*\\]\\]", TG_HYPERLINK); + new Terminator(PRESERVE, "\\[\\[([\\s\\S]+)\\][ \\t\\r\\n]*\\[([\\s\\S]+)\\]\\]", TG_HYPERLINK); + + public static final Terminator orgTerminator2 = + new Terminator(PRESERVE, "\\[\\[([\\s\\S]+)\\]\\]", TG_HYPERLINK); private String label; private String URL; @Override - public String compileMd() { - return ""; + public String toMD() { + + if (URL.startsWith("id:")) + return label; // TODO + + return "[" + label + "]("+ URL + ")"; } - public static Hyperlink fromOrg(TokenizerMatch tokenizerMatch) throws InvalidSyntaxException { + public static Hyperlink fromOrg(TokenizerMatch tokenizerMatch) { Hyperlink hyperlink = new Hyperlink(); - hyperlink.parseOrgSyntax(tokenizerMatch); + hyperlink.parseOrg(tokenizerMatch); return hyperlink; } - private void parseOrgSyntax(TokenizerMatch tokenizerMatch) throws InvalidSyntaxException { -// Tokenizer tokenizer = new Tokenizer(tokenizerMatch.reminder); -// Terminator linkSeparator = tokenizer.addTerminator("][", PRESERVE); -// -// URL = tokenizer.expectAndConsumeNextTerminatorToken(null).token; -// -// if (tokenizer.hasMoreContent()){ // link label is optional -// tokenizer.expectAndConsumeNextTerminatorToken(linkSeparator); -// label = tokenizer.expectAndConsumeNextTerminatorToken(null).token; -// } + private void parseOrg(TokenizerMatch tokenizerMatch) { + String[] regExpGroups = tokenizerMatch.getRegExpGroups(); + URL = regExpGroups[0]; + if (tokenizerMatch.terminator == orgTerminator){ + label = regExpGroups[1]; + } + } }