Skip to content

Commit e4c4ea3

Browse files
committed
[apacheGH-8313] Allow use of custom HTML-Tags in PHP
-register CustomHtmlExtension to x-php5 mimeType -UnknownAttribute hint used to be at wrong position in source when embedded in PHP Example: customs.json ```json { "elements": { "y-customdefined": { "attributes": { "exists": {} } } }, "attributes": {"globaldefined": {}} } ``` PHP script including custom tags, so far none of the tags defined in customs.json will be valid ```php <x-customnotdefined><?php echo 'test'; ?></x-customnotdefined> <y-customdefined exists="" noexists=""><?php echo 'test'; ?></y-customdefined> <y-customdefined exists=""></y-customdefined> <y-customdefined globaldefined=""></y-customdefined> <y-customdefined noexists=""><?php echo 'test'; ?></y-customdefined> ```
1 parent 4bc8045 commit e4c4ea3

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ide/html.custom/src/org/netbeans/modules/html/custom/CustomHtmlExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
* @author marek
5757
*/
5858
@MimeRegistrations({
59-
@MimeRegistration(mimeType = "text/html", service = HtmlExtension.class)
59+
@MimeRegistration(mimeType = "text/html", service = HtmlExtension.class),
60+
@MimeRegistration(mimeType = "text/x-php5", service = HtmlExtension.class)
6061
})
6162
public class CustomHtmlExtension extends HtmlExtension {
6263

@@ -76,7 +77,7 @@ private Configuration getConfiguration(HtmlSource source) {
7677
if (cache == null) {
7778
//no cache - create
7879
FileObject sourceFileObject = source.getSourceFileObject();
79-
Project project = sourceFileObject == null ? null : FileOwnerQuery.getOwner(sourceFileObject);
80+
Project project = sourceFileObject == null ? null : FileOwnerQuery.getOwner(sourceFileObject);
8081
Configuration conf = project == null ? Configuration.EMPTY : Configuration.get(project);
8182
cache = Pair.of(source, conf);
8283
return cache.second();

ide/html.custom/src/org/netbeans/modules/html/custom/hints/CheckerElementVisitor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public static ElementVisitor getChecker(RuleContext context, Configuration conf,
4343
Collection<ElementVisitor> visitors = new ArrayList<>();
4444
visitors.add(new UnknownAttributesChecker(context, conf, snapshot, hints));
4545
visitors.add(new MissingRequiredAttributeChecker(context, conf, snapshot, hints));
46-
46+
4747
return new AggregatedVisitor(visitors);
4848
}
49-
49+
5050
public static class AggregatedVisitor implements ElementVisitor {
5151

5252
private final Collection<ElementVisitor> visitors;
5353

5454
public AggregatedVisitor(Collection<ElementVisitor> visitors) {
5555
this.visitors = visitors;
5656
}
57-
57+
5858
@Override
5959
public void visit(Element node) {
6060
for(ElementVisitor visitor : visitors) {
@@ -63,9 +63,9 @@ public void visit(Element node) {
6363
}
6464

6565
}
66-
66+
6767
protected abstract static class Checker implements ElementVisitor {
68-
68+
6969
protected RuleContext context;
7070
protected Configuration conf;
7171
protected Snapshot snapshot;
@@ -116,7 +116,7 @@ public void visit(Element node) {
116116
boolean lineHint = false;
117117

118118
//use the whole element offsetrange so multiple unknown attributes can be handled
119-
OffsetRange range = new OffsetRange(snapshot.getEmbeddedOffset(ot.from()), snapshot.getEmbeddedOffset(ot.to()));
119+
OffsetRange range = new OffsetRange(snapshot.getOriginalOffset(ot.from()), snapshot.getOriginalOffset(ot.to()));
120120
hints.add(new UnknownAttributes(unknownAttributeNames, tagModel.getName(), context, range, lineHint));
121121
}
122122
}
@@ -125,7 +125,7 @@ public void visit(Element node) {
125125
}
126126
}
127127

128-
private static class MissingRequiredAttributeChecker extends Checker {
128+
private static class MissingRequiredAttributeChecker extends Checker {
129129

130130
public MissingRequiredAttributeChecker(RuleContext context, Configuration conf, Snapshot snapshot, List<Hint> hints) {
131131
super(context, conf, snapshot, hints);
@@ -157,6 +157,6 @@ public void visit(Element node) {
157157
}
158158
}
159159
}
160-
161-
160+
161+
162162
}

0 commit comments

Comments
 (0)