forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: BytebuddyAgent Unable to use in the JRE environment so remove it (…
…halo-dev#1429) * fix: BytebuddyAgent Unable to use in the JRE environment so remove it * feat: Add package info
- Loading branch information
Showing
16 changed files
with
1,055 additions
and
144 deletions.
There are no files selected for viewing
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
140 changes: 140 additions & 0 deletions
140
src/main/java/run/halo/app/utils/footnotes/Footnote.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,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
171
src/main/java/run/halo/app/utils/footnotes/FootnoteBlock.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,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); | ||
} | ||
} |
Oops, something went wrong.