respec icon indicating copy to clipboard operation
respec copied to clipboard

Error raised when cross-referencing best practices

Open andrea-perego opened this issue 4 years ago • 2 comments

Important info

  • URL to affected spec: https://w3c.github.io/sdw/bp/
  • ReSpec version: 25.6.0 (but the problem is with 26.0.0)
  • [x] I did a "hard refresh", but it's still busted.

Description of problem

What happened (e.g., it crashed)?:

ReSpec does not seem to support cross-referencing of best practices via an empty a element, as done instead for sections and figures.

To address this issue, the SDW Best Practices (https://w3c.github.io/sdw/bp/) have been using a jQuery script. Until ReSpec 25.6.0 this worked without raising any errors/warnings.

Testing the switch to respec-w3c, the original script has been replaced with an equivalent one, not making use of jQuery.

However, for each of the cross-refs (>30), ReSpec returns the following error, before the custom script is run via postProcess:

ReSpec doesn't support expanding this kind of reference.

Expected behavior (e.g., it shouldn't crash):

Ideally, ReSpec should provide support for best practices cross-referencing.

Otherwise, it should allow the use of custom scripts for the same purpose, without raising errors or warnings.

Optional, steps to reproduce:

  1. ...

andrea-perego avatar Jan 30 '21 10:01 andrea-perego

@andrea-perego I checked the linked PR, and I think you need to use both preProcess and postProcess (and also include jQuery if you wish to use it). I also had to fix a few syntax errors due to quote-mismatches. This is meant as a workaround until we add native support for best practices expansion (right now BP documents aren't well supported in ReSpec).

This patch seems to work (no errors at least):
diff --git a/bp/index.html b/bp/index.html
index 7354108..90ce477 100644
--- a/bp/index.html
+++ b/bp/index.html
@@ -6,6 +6,7 @@
 <!--
     <script src="https://www.w3.org/Tools/respec/respec-w3c-common" class="remove" defer></script>
 -->
+    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
     <script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" defer></script>
     <script class="remove" src="bpconfig.js"></script>
     <script>
@@ -21,7 +22,6 @@
 
 ********************************************************************************* */
 
-/* **
 
 function popCrossRefs() {
   $('a[href^="#"]').each( function () {
@@ -29,11 +29,11 @@ function popCrossRefs() {
     var id = href.trim().replace('#','');
     var text = $(this).text();
     if (text.trim().length == 0 && id.length > 0 && ( $(href).hasClass('example') || $(href).hasClass('practicelab') )) {
-      var label = $('.example:has(#' + id + ') > .example-title, *[id="' + id + '"].example > .example-title, *[id="' + id + '"].illegal-example > .example-title).text();
+      var label = $('.example:has(#' + id + ') > .example-title, *[id="' + id + '"].example > .example-title, *[id="' + id + '"].illegal-example > .example-title)').text();
       if (label.trim().length > 0) {
         $(this).text(label);
       }
-      var label = $(*[id="' + id + '"].practicelab').text();
+      var label = $('*[id="' + id + '"].practicelab').text();
       if (label.trim().length > 0) {
         $(this).text(label);
       }
@@ -41,11 +41,6 @@ function popCrossRefs() {
   } );
 }
 
-$(document).ready( function() {
-  popCrossRefs();
-});
-** */
-
 var bp = new Array();
 
 function getBPs() {
@@ -81,6 +76,9 @@ function bpCrossRefs() {
   }
 }
 
+respecConfig.preProcess = [bpCrossRefs];
+respecConfig.postProcess = [popCrossRefs];
+
 // @andrea-perego
     </script>
     <script class="remove" src="benefits.js"></script>
@@ -4900,9 +4898,6 @@ resource:d45678 dqv:hasQualityMeasurement [ a dqv:QualityMeasurement ;
 
     </section>
 
-<script>
-bpCrossRefs();
-</script>
 
   </body>
 </html>

sidvishnoi avatar Mar 03 '21 10:03 sidvishnoi

Thanks, @sidvishnoi . We'll do as you suggest.

andrea-perego avatar Mar 03 '21 12:03 andrea-perego