-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow BlockParsers to return definitions (for lookup during inline pa…
…rsing)
- Loading branch information
Showing
15 changed files
with
166 additions
and
55 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
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
33 changes: 33 additions & 0 deletions
33
commonmark/src/main/java/org/commonmark/internal/Definitions.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,33 @@ | ||
package org.commonmark.internal; | ||
|
||
import org.commonmark.node.DefinitionMap; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Definitions { | ||
|
||
private final Map<Class<?>, DefinitionMap<?>> definitionsByType = new HashMap<>(); | ||
|
||
public <D> void addDefinitions(DefinitionMap<D> definitionMap) { | ||
var existingMap = getMap(definitionMap.getType()); | ||
if (existingMap == null) { | ||
definitionsByType.put(definitionMap.getType(), definitionMap); | ||
} else { | ||
existingMap.addAll(definitionMap); | ||
} | ||
} | ||
|
||
public <V> V getDefinition(Class<V> type, String label) { | ||
var definitionMap = getMap(type); | ||
if (definitionMap == null) { | ||
return null; | ||
} | ||
return definitionMap.get(label); | ||
} | ||
|
||
private <V> DefinitionMap<V> getMap(Class<V> type) { | ||
//noinspection unchecked | ||
return (DefinitionMap<V>) definitionsByType.get(type); | ||
} | ||
} |
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
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
Oops, something went wrong.