-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from vsch/master
Update Master
- Loading branch information
Showing
33 changed files
with
540 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
flexmark-ext-resizable-image/flexmark-ext-resizable-image.iml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module" module-name="flexmark" /> | ||
<orderEntry type="module" module-name="flexmark-util-ast" /> | ||
<orderEntry type="module" module-name="flexmark-util-builder" /> | ||
<orderEntry type="module" module-name="flexmark-util-data" /> | ||
<orderEntry type="module" module-name="flexmark-util-dependency" /> | ||
<orderEntry type="module" module-name="flexmark-util-html" /> | ||
<orderEntry type="module" module-name="flexmark-util-misc" /> | ||
<orderEntry type="module" module-name="flexmark-util-sequence" /> | ||
<orderEntry type="module" module-name="flexmark-util-visitor" /> | ||
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" /> | ||
<orderEntry type="module" module-name="flexmark-core-test" scope="TEST" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
<orderEntry type="library" name="org.jetbrains:annotations" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.vladsch.flexmark</groupId> | ||
<artifactId>flexmark-java</artifactId> | ||
<version>0.62.2</version> | ||
</parent> | ||
|
||
<artifactId>flexmark-ext-resizable-image</artifactId> | ||
<name>flexmark-java extension for image's size</name> | ||
<description>flexmark-java extension to set the size of the images</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.vladsch.flexmark</groupId> | ||
<artifactId>flexmark</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.vladsch.flexmark</groupId> | ||
<artifactId>flexmark-test-util</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.vladsch.flexmark</groupId> | ||
<artifactId>flexmark-core-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
...esizable-image/src/main/java/com/vladsch/flexmark/ext/resizable/image/ResizableImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.vladsch.flexmark.ext.resizable.image; | ||
|
||
import com.vladsch.flexmark.util.ast.DoNotDecorate; | ||
import com.vladsch.flexmark.util.ast.Node; | ||
import com.vladsch.flexmark.util.sequence.BasedSequence; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ResizableImage extends Node implements DoNotDecorate { | ||
protected BasedSequence source = BasedSequence.NULL; | ||
protected BasedSequence text = BasedSequence.NULL; | ||
protected BasedSequence width = BasedSequence.NULL; | ||
protected BasedSequence height = BasedSequence.NULL; | ||
|
||
@NotNull | ||
@Override | ||
public BasedSequence[] getSegments() { | ||
return new BasedSequence[] { text, source, width, height }; | ||
} | ||
|
||
public ResizableImage(BasedSequence text, BasedSequence source, BasedSequence width, BasedSequence height) { | ||
super(spanningChars(text, source, width, height)); | ||
this.source = source; | ||
this.text = text; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public BasedSequence getText() { | ||
return text; | ||
} | ||
|
||
public BasedSequence getSource() { | ||
return source; | ||
} | ||
|
||
public BasedSequence getWidth() { | ||
return width; | ||
} | ||
|
||
public BasedSequence getHeight() { | ||
return height; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...image/src/main/java/com/vladsch/flexmark/ext/resizable/image/ResizableImageExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.vladsch.flexmark.ext.resizable.image; | ||
|
||
import com.vladsch.flexmark.ext.resizable.image.internal.ResizableImageInlineParserExtension; | ||
import com.vladsch.flexmark.ext.resizable.image.internal.ResizableImageNodeRenderer; | ||
import com.vladsch.flexmark.html.HtmlRenderer; | ||
import com.vladsch.flexmark.parser.Parser; | ||
import com.vladsch.flexmark.util.data.MutableDataHolder; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ResizableImageExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension { | ||
|
||
private ResizableImageExtension() { | ||
} | ||
|
||
public static ResizableImageExtension create() { | ||
return new ResizableImageExtension(); | ||
} | ||
|
||
@Override | ||
public void rendererOptions(@NotNull MutableDataHolder options) { | ||
|
||
} | ||
|
||
@Override | ||
public void parserOptions(MutableDataHolder options) { | ||
|
||
} | ||
|
||
@Override | ||
public void extend(Parser.Builder parserBuilder) { | ||
parserBuilder.customInlineParserExtensionFactory(new ResizableImageInlineParserExtension.Factory()); | ||
} | ||
|
||
@Override | ||
public void extend(@NotNull HtmlRenderer.Builder htmlRendererBuilder, @NotNull String rendererType) { | ||
if (htmlRendererBuilder.isRendererType("HTML")) { | ||
htmlRendererBuilder.nodeRendererFactory(new ResizableImageNodeRenderer.Factory()); | ||
} else if (htmlRendererBuilder.isRendererType("JIRA")) { | ||
return; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...e-image/src/main/java/com/vladsch/flexmark/ext/resizable/image/ResizableImageVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.vladsch.flexmark.ext.resizable.image; | ||
|
||
public interface ResizableImageVisitor { | ||
void visit(ResizableImage node); | ||
} |
11 changes: 11 additions & 0 deletions
11
...mage/src/main/java/com/vladsch/flexmark/ext/resizable/image/ResizableImageVisitorExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vladsch.flexmark.ext.resizable.image; | ||
|
||
import com.vladsch.flexmark.util.ast.VisitHandler; | ||
|
||
public class ResizableImageVisitorExt { | ||
public static <V extends ResizableImageVisitor> VisitHandler<?>[] VISIT_HANDLERS(V visitor) { | ||
return new VisitHandler<?>[] { | ||
new VisitHandler<>(ResizableImage.class, visitor::visit), | ||
}; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...om/vladsch/flexmark/ext/resizable/image/internal/ResizableImageInlineParserExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.vladsch.flexmark.ext.resizable.image.internal; | ||
|
||
import com.vladsch.flexmark.ext.resizable.image.ResizableImage; | ||
import com.vladsch.flexmark.parser.InlineParser; | ||
import com.vladsch.flexmark.parser.InlineParserExtension; | ||
import com.vladsch.flexmark.parser.InlineParserExtensionFactory; | ||
import com.vladsch.flexmark.parser.LightInlineParser; | ||
import com.vladsch.flexmark.util.sequence.BasedSequence; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
public class ResizableImageInlineParserExtension implements InlineParserExtension { | ||
final public static Pattern IMAGE_PATTERN = Pattern.compile("\\!\\[(\\S*)\\]\\((\\S*)\\s*=*(\\d*)x*(\\d*)\\)", | ||
Pattern.CASE_INSENSITIVE); | ||
|
||
public ResizableImageInlineParserExtension(LightInlineParser inlineParser) { | ||
} | ||
|
||
@Override | ||
public void finalizeDocument(@NotNull InlineParser inlineParser) { | ||
} | ||
|
||
@Override | ||
public void finalizeBlock(@NotNull InlineParser inlineParser) { | ||
} | ||
|
||
@Override | ||
public boolean parse(@NotNull LightInlineParser inlineParser) { | ||
int index = inlineParser.getIndex(); | ||
char c = inlineParser.getInput().charAt(index + 1); | ||
if (c == '[') { | ||
BasedSequence[] matches = inlineParser.matchWithGroups(IMAGE_PATTERN); | ||
if (matches != null) { | ||
inlineParser.flushTextNode(); | ||
|
||
BasedSequence text = matches[1]; | ||
BasedSequence source = matches[2]; | ||
BasedSequence width = matches[3]; | ||
BasedSequence height = matches[4]; | ||
|
||
ResizableImage image = new ResizableImage(text, source, width, height); | ||
inlineParser.getBlock().appendChild(image); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static class Factory implements InlineParserExtensionFactory { | ||
@Nullable | ||
@Override | ||
public Set<Class<?>> getAfterDependents() { | ||
return null; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CharSequence getCharacters() { | ||
return "!"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Set<Class<?>> getBeforeDependents() { | ||
return null; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public InlineParserExtension apply(@NotNull LightInlineParser lightInlineParser) { | ||
return new ResizableImageInlineParserExtension(lightInlineParser); | ||
} | ||
|
||
@Override | ||
public boolean affectsGlobalScope() { | ||
return false; | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...in/java/com/vladsch/flexmark/ext/resizable/image/internal/ResizableImageNodeRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.vladsch.flexmark.ext.resizable.image.internal; | ||
|
||
import com.vladsch.flexmark.ext.resizable.image.ResizableImage; | ||
import com.vladsch.flexmark.html.HtmlWriter; | ||
import com.vladsch.flexmark.html.renderer.LinkType; | ||
import com.vladsch.flexmark.html.renderer.NodeRenderer; | ||
import com.vladsch.flexmark.html.renderer.NodeRendererContext; | ||
import com.vladsch.flexmark.html.renderer.NodeRendererFactory; | ||
import com.vladsch.flexmark.html.renderer.NodeRenderingHandler; | ||
import com.vladsch.flexmark.html.renderer.ResolvedLink; | ||
import com.vladsch.flexmark.util.data.DataHolder; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ResizableImageNodeRenderer implements NodeRenderer | ||
{ | ||
public ResizableImageNodeRenderer(DataHolder options) { | ||
} | ||
|
||
@Override | ||
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() { | ||
Set<NodeRenderingHandler<?>> set = new HashSet<>(); | ||
// @formatter:off | ||
set.add(new NodeRenderingHandler<>(ResizableImage.class, ResizableImageNodeRenderer.this::render)); | ||
// @formatter:on | ||
return set; | ||
} | ||
|
||
public void render(ResizableImage node, NodeRendererContext context, HtmlWriter html) { | ||
if (context.isDoNotRenderLinks()) { | ||
context.renderChildren(node); | ||
} else { | ||
ResolvedLink link = context.resolveLink(LinkType.IMAGE, node.getSource(), true); | ||
html.srcPos(node.getChars()) | ||
.attr("src", link.getUrl()); | ||
if (node.getText().isNotEmpty()){ | ||
html.attr("alt", node.getText()); | ||
} | ||
if (node.getWidth().isNotEmpty()){ | ||
html.attr("width", node.getWidth() + "px"); | ||
} | ||
if (node.getHeight().isNotEmpty()){ | ||
html.attr("height", node.getHeight() + "px"); | ||
} | ||
html.withAttr().tag("img"); | ||
html.tag("/img"); | ||
} | ||
} | ||
|
||
public static class Factory implements NodeRendererFactory { | ||
@NotNull | ||
@Override | ||
public NodeRenderer apply(@NotNull DataHolder options) { | ||
return new ResizableImageNodeRenderer(options); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
flexmark-ext-resizable-image/src/main/javadoc/overview.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<p><strong>flexmark-java extension enables to set width and height for images by stating them | ||
as ![text](/src =WxH) which is used in Azure DevOps markdown.</strong></p> | ||
<p>Converts ![text](/src =WxH) into image with width = W and height = H. | ||
Also added support for image`s relative paths from Azure DevOps repository.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**flexmark-java extension enables to set width and height for images by stating them as ![text](/src =WxH) which is used in Azure DevOps markdown.** | ||
|
||
Converts ![text](/src =WxH) into image with width = W and height = H. | ||
Also added support for image`s relative paths from Azure DevOps repository. |
Oops, something went wrong.