Skip to content

Commit

Permalink
Closes #157
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Mar 31, 2021
1 parent a61c04f commit 1096519
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Core/src/ca/uqac/lif/textidote/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
TeXtidote, a linter for LaTeX documents
Copyright (C) 2018 Sylvain Hallé
Copyright (C) 2018-2021 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
25 changes: 24 additions & 1 deletion Source/Core/src/ca/uqac/lif/textidote/as/AnnotatedString.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
TeXtidote, a linter for LaTeX documents
Copyright (C) 2018 Sylvain Hallé
Copyright (C) 2018-2021 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -72,6 +72,11 @@ public class AnnotatedString
* The size (in bytes) of the OS-dependent line separator
*/
public static final transient int CRLF_SIZE = System.getProperty("line.separator").length();

/**
* The OS-dependent line separator, expressed as a regular expression
*/
public static final transient String CRLF_REGEX = getCrlfRegex(CRLF);

/**
* Creates a new empty annotated string
Expand Down Expand Up @@ -908,4 +913,22 @@ public int getOffset(Position p)
}
return -1;
}

/**
* Turns the OS-dependent CRLF character into a regular expression.
* @param s The character
* @return The regex
*/
protected static String getCrlfRegex(String s)
{
if (s.compareTo("\\r\\n") == 0)
{
return ("\\\\r\\\\n");
}
if (s.compareTo("\\r") == 0)
{
return ("\\\\r");
}
return ("\\\\n");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
TeXtidote, a linter for LaTeX documents
Copyright (C) 2018-2019 Sylvain Hallé
Copyright (C) 2018-2021 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
TeXtidote, a linter for LaTeX documents
Copyright (C) 2018-2019 Sylvain Hallé
Copyright (C) 2018-2021 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -122,6 +122,7 @@ public class MarkdownCleaner extends TextCleaner
as_out = as_out.replaceAll("`.*?`", "X");
as_out = as_out.replaceAll("!\\[(.*?)\\]\\(.*?\\)", "$1"); // images
as_out = as_out.replaceAll("\\[(.*?)\\]\\(.*?\\)", "$1"); // links
as_out = as_out.replaceAll("^ .*$", ""); // indented code blocks
as_out = as_out.replaceAll("^\\s*?- ", "• ");
as_out = as_out.replaceAll("^\\s*#*\\s*", "");
as_out = as_out.replaceAll("^\\s*=*\\s*$", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public void testRemoveBackticks1() throws TextCleanerException
AnnotatedString as = detexer.clean(AnnotatedString.read(new Scanner("This is `foo`.")));
assertEquals("This is X.", as.toString());
}

@Test
public void testRemoveIndentedBlocks1() throws TextCleanerException
{
MarkdownCleaner detexer = new MarkdownCleaner();
AnnotatedString as = detexer.clean(AnnotatedString.read(new Scanner("Here are a few words." + CRLF + CRLF + " Some code block" + CRLF + CRLF + "Here are some more.")));
assertEquals("Here are a few words." + CRLF + CRLF + CRLF + CRLF + "Here are some more.", as.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
TeXtidote, a linter for LaTeX documents
Copyright (C) 2018 Sylvain Hallé
Copyright (C) 2018-2021 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 1096519

Please sign in to comment.