Skip to content

Commit

Permalink
fix: BytebuddyAgent Unable to use in the JRE environment so remove it (
Browse files Browse the repository at this point in the history
…halo-dev#1429)

* fix: BytebuddyAgent Unable to use in the JRE environment so remove it

* feat: Add package info
  • Loading branch information
guqing authored Jul 20, 2021
1 parent f42d4e2 commit 1ae1865
Show file tree
Hide file tree
Showing 16 changed files with 1,055 additions and 144 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ ext {
huaweiObsVersion = "3.19.7"
templateInheritanceVersion = "0.4.RELEASE"
jsoupVersion = "1.13.1"
byteBuddyAgentVersion = "1.10.22"
}

dependencies {
Expand Down Expand Up @@ -142,15 +141,12 @@ dependencies {
implementation "com.vladsch.flexmark:flexmark-ext-superscript:$flexmarkVersion"
implementation "com.vladsch.flexmark:flexmark-ext-yaml-front-matter:$flexmarkVersion"
implementation "com.vladsch.flexmark:flexmark-ext-gitlab:$flexmarkVersion"
implementation "com.vladsch.flexmark:flexmark-ext-footnotes:$flexmarkVersion"


implementation "kr.pe.kwonnam.freemarker:freemarker-template-inheritance:$templateInheritanceVersion"
implementation "net.coobird:thumbnailator:$thumbnailatorVersion"
implementation "net.sf.image4j:image4j:$image4jVersion"
implementation "org.flywaydb:flyway-core:$flywayVersion"
implementation "com.google.zxing:core:$zxingVersion"
implementation "net.bytebuddy:byte-buddy-agent:$byteBuddyAgentVersion"

implementation "org.iq80.leveldb:leveldb:$levelDbVersion"
runtimeOnly "com.h2database:h2:$h2Version"
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/run/halo/app/utils/MarkdownUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.vladsch.flexmark.ext.emoji.EmojiImageType;
import com.vladsch.flexmark.ext.emoji.EmojiShortcutType;
import com.vladsch.flexmark.ext.escaped.character.EscapedCharacterExtension;
import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
import com.vladsch.flexmark.ext.gitlab.GitLabExtension;
Expand All @@ -30,6 +29,7 @@
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import run.halo.app.model.support.HaloConst;
import run.halo.app.utils.footnotes.FootnoteExtension;

/**
* Markdown utils.
Expand Down Expand Up @@ -111,8 +111,6 @@ public static String renderHtml(String markdown) {
markdown = markdown
.replaceAll(HaloConst.YOUTUBE_VIDEO_REG_PATTERN, HaloConst.YOUTUBE_VIDEO_IFRAME);
}
// footnote render method delegation.
FootnoteNodeRendererInterceptor.doDelegationMethod();

Node document = PARSER.parse(markdown);

Expand Down
140 changes: 140 additions & 0 deletions src/main/java/run/halo/app/utils/footnotes/Footnote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package run.halo.app.utils.footnotes;

import com.vladsch.flexmark.ast.LinkRendered;
import com.vladsch.flexmark.util.ast.DelimitedNode;
import com.vladsch.flexmark.util.ast.DoNotDecorate;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.ReferencingNode;
import com.vladsch.flexmark.util.sequence.BasedSequence;
import org.jetbrains.annotations.NotNull;
import run.halo.app.utils.footnotes.internal.FootnoteRepository;

/**
* A Footnote referencing node
*/
public class Footnote extends Node implements DelimitedNode, DoNotDecorate, LinkRendered,
ReferencingNode<FootnoteRepository, FootnoteBlock> {
protected BasedSequence openingMarker = BasedSequence.NULL;
protected BasedSequence text = BasedSequence.NULL;
protected BasedSequence closingMarker = BasedSequence.NULL;
protected FootnoteBlock footnoteBlock;

public int getReferenceOrdinal() {
return referenceOrdinal;
}

public void setReferenceOrdinal(int referenceOrdinal) {
this.referenceOrdinal = referenceOrdinal;
}

protected int referenceOrdinal;

@NotNull
@Override
public BasedSequence getReference() {
return text;
}

@Override
public FootnoteBlock getReferenceNode(Document document) {
if (footnoteBlock != null || text.isEmpty()) {
return footnoteBlock;
}
footnoteBlock = getFootnoteBlock(FootnoteExtension.FOOTNOTES.get(document));
return footnoteBlock;
}

@Override
public FootnoteBlock getReferenceNode(FootnoteRepository repository) {
if (footnoteBlock != null || text.isEmpty()) {
return footnoteBlock;
}
footnoteBlock = getFootnoteBlock(repository);
return footnoteBlock;
}

@Override
public boolean isDefined() {
return footnoteBlock != null;
}

/**
* @return true if this node will be rendered as text because it depends on a reference which
* is not defined.
*/
@Override
public boolean isTentative() {
return footnoteBlock == null;
}

public FootnoteBlock getFootnoteBlock(FootnoteRepository footnoteRepository) {
return text.isEmpty() ? null : footnoteRepository.get(text.toString());
}

public FootnoteBlock getFootnoteBlock() {
return footnoteBlock;
}

public void setFootnoteBlock(FootnoteBlock footnoteBlock) {
this.footnoteBlock = footnoteBlock;
}

@NotNull
@Override
public BasedSequence[] getSegments() {
return new BasedSequence[] {openingMarker, text, closingMarker};
}

@Override
public void getAstExtra(@NotNull StringBuilder out) {
out.append(" ordinal: ")
.append(footnoteBlock != null ? footnoteBlock.getFootnoteOrdinal() : 0).append(" ");
delimitedSegmentSpanChars(out, openingMarker, text, closingMarker, "text");
}

public Footnote() {
}

public Footnote(BasedSequence chars) {
super(chars);
}

public Footnote(BasedSequence openingMarker, BasedSequence text, BasedSequence closingMarker) {
super(openingMarker
.baseSubSequence(openingMarker.getStartOffset(), closingMarker.getEndOffset()));
this.openingMarker = openingMarker;
this.text = text;
this.closingMarker = closingMarker;
}

@Override
public BasedSequence getOpeningMarker() {
return openingMarker;
}

@Override
public void setOpeningMarker(BasedSequence openingMarker) {
this.openingMarker = openingMarker;
}

@Override
public BasedSequence getText() {
return text;
}

@Override
public void setText(BasedSequence text) {
this.text = text;
}

@Override
public BasedSequence getClosingMarker() {
return closingMarker;
}

@Override
public void setClosingMarker(BasedSequence closingMarker) {
this.closingMarker = closingMarker;
}
}
171 changes: 171 additions & 0 deletions src/main/java/run/halo/app/utils/footnotes/FootnoteBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package run.halo.app.utils.footnotes;

import com.vladsch.flexmark.ast.Paragraph;
import com.vladsch.flexmark.ast.ParagraphItemContainer;
import com.vladsch.flexmark.parser.ListOptions;
import com.vladsch.flexmark.util.ast.Block;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.ReferenceNode;
import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.sequence.BasedSequence;
import com.vladsch.flexmark.util.sequence.SequenceUtils;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import run.halo.app.utils.footnotes.internal.FootnoteRepository;

/**
* A Footnote definition node containing text and other inline nodes nodes as children.
*/
public class FootnoteBlock extends Block
implements ReferenceNode<FootnoteRepository, FootnoteBlock, Footnote>, ParagraphItemContainer {

protected BasedSequence openingMarker = BasedSequence.NULL;
protected BasedSequence text = BasedSequence.NULL;
protected BasedSequence closingMarker = BasedSequence.NULL;
protected BasedSequence footnote = BasedSequence.NULL;
private int footnoteOrdinal = 0;
private int firstReferenceOffset = Integer.MAX_VALUE;
private int footnoteReferences = 0;

@Override
public int compareTo(FootnoteBlock other) {
return SequenceUtils.compare(text, other.text, true);
}

public int getFootnoteReferences() {
return footnoteReferences;
}

public void setFootnoteReferences(int footnoteReferences) {
this.footnoteReferences = footnoteReferences;
}

@Nullable
@Override
public Footnote getReferencingNode(@NotNull Node node) {
return node instanceof Footnote ? (Footnote) node : null;
}

public int getFirstReferenceOffset() {
return firstReferenceOffset;
}

public void setFirstReferenceOffset(int firstReferenceOffset) {
this.firstReferenceOffset = firstReferenceOffset;
}

public void addFirstReferenceOffset(int firstReferenceOffset) {
if (this.firstReferenceOffset < firstReferenceOffset) {
this.firstReferenceOffset = firstReferenceOffset;
}
}

public boolean isReferenced() {
return this.firstReferenceOffset < Integer.MAX_VALUE;
}

public int getFootnoteOrdinal() {
return footnoteOrdinal;
}

public void setFootnoteOrdinal(int footnoteOrdinal) {
this.footnoteOrdinal = footnoteOrdinal;
}

@Override
public void getAstExtra(@NotNull StringBuilder out) {
out.append(" ordinal: ").append(footnoteOrdinal).append(" ");
segmentSpan(out, openingMarker, "open");
segmentSpan(out, text, "text");
segmentSpan(out, closingMarker, "close");
segmentSpan(out, footnote, "footnote");
}

@NotNull
@Override
public BasedSequence[] getSegments() {
return new BasedSequence[] {openingMarker, text, closingMarker, footnote};
}

public FootnoteBlock() {
}

public FootnoteBlock(BasedSequence chars) {
super(chars);
}

public BasedSequence getOpeningMarker() {
return openingMarker;
}

public void setOpeningMarker(BasedSequence openingMarker) {
this.openingMarker = openingMarker;
}

public BasedSequence getText() {
return text;
}

public void setText(BasedSequence text) {
this.text = text;
}

public BasedSequence getClosingMarker() {
return closingMarker;
}

public void setClosingMarker(BasedSequence closingMarker) {
this.closingMarker = closingMarker;
}

public BasedSequence getFootnote() {
return footnote;
}

public void setFootnote(BasedSequence footnote) {
this.footnote = footnote;
}

@Override
public boolean isItemParagraph(Paragraph node) {
return node == getFirstChild();
}

@Override
public boolean isParagraphWrappingDisabled(Paragraph node, ListOptions listOptions,
DataHolder options) {
return false;
}

@Override
public boolean isParagraphInTightListItem(Paragraph node) {
return false;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FootnoteBlock that = (FootnoteBlock) o;
return footnoteOrdinal == that.footnoteOrdinal
&& firstReferenceOffset == that.firstReferenceOffset
&& footnoteReferences == that.footnoteReferences
&& Objects.equals(openingMarker, that.openingMarker)
&& Objects.equals(text, that.text)
&& Objects.equals(closingMarker, that.closingMarker)
&& Objects.equals(footnote, that.footnote);
}

@Override
public int hashCode() {
return Objects
.hash(openingMarker, text, closingMarker, footnote, footnoteOrdinal,
firstReferenceOffset,
footnoteReferences);
}
}
Loading

0 comments on commit 1ae1865

Please sign in to comment.