Skip to content

Commit 46f55f5

Browse files
committed
minor #11099 Improved the highlighting of JS examples in Mercure docs (javiereguiluz)
This PR was merged into the 4.2 branch. Discussion ---------- Improved the highlighting of JS examples in Mercure docs I was wrong and I told Kévin to include `<script>` in the JS code samples ... this prevents highlighting from working. See https://symfony.com/doc/current/mercure.html#subscribing Commits ------- 95ac954 Improved the highlighting of JS examples in Mercure docs
2 parents 1b731b2 + 95ac954 commit 46f55f5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

mercure.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,30 +189,29 @@ Subscribing to updates in JavaScript is straightforward:
189189

190190
.. code-block:: javascript
191191
192-
<script>
193192
const es = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
194193
es.onmessage = e => {
195194
// Will be called every time an update is published by the server
196195
console.log(JSON.parse(e.data));
197196
}
198-
</script>
199197
200198
Mercure also allows to subscribe to several topics,
201199
and to use URI Templates as patterns:
202200

203201
.. code-block:: javascript
204202
205-
<script>
206-
const u = new URL('http://localhost:3000/hub'); // URL is a built-in JavaScript class to manipulate URLs
203+
// URL is a built-in JavaScript class to manipulate URLs
204+
const u = new URL('http://localhost:3000/hub');
207205
u.searchParams.append('topic', 'http://example.com/books/1');
208-
u.searchParams.append('topic', 'http://example.com/books/2'); // Subscribe to updates of several Book resources
209-
u.searchParams.append('topic', 'http://example.com/reviews/{id}'); // All Review resources will match this pattern
206+
// Subscribe to updates of several Book resources
207+
u.searchParams.append('topic', 'http://example.com/books/2');
208+
// All Review resources will match this pattern
209+
u.searchParams.append('topic', 'http://example.com/reviews/{id}');
210210
211211
const es = new EventSource(u);
212212
es.onmessage = e => {
213213
console.log(JSON.parse(e.data));
214214
}
215-
</script>
216215
217216
.. tip::
218217

@@ -293,7 +292,7 @@ by using the ``AbstractController::addLink`` helper method::
293292
public function __invoke(Request $request): JsonResponse
294293
{
295294
// This parameter is automatically created by the MercureBundle
296-
$hubUrl = $this->getParameter('mercure.default_hub');
295+
$hubUrl = $this->getParameter('mercure.default_hub');
297296

298297
// Link: <http://localhost:3000/hub>; rel="mercure"
299298
$this->addLink($request, new Link('mercure', $hubUrl));
@@ -310,7 +309,6 @@ and to subscribe to it:
310309

311310
.. code-block:: javascript
312311
313-
<script>
314312
// Fetch the original resource served by the Symfony web API
315313
fetch('/books/1') // Has Link: <http://localhost:3000/hub>; rel="mercure"
316314
.then(response => {
@@ -325,7 +323,6 @@ and to subscribe to it:
325323
const es = new EventSource(h);
326324
es.onmessage = e => console.log(e.data);
327325
});
328-
</script>
329326
330327
Authorization
331328
-------------

0 commit comments

Comments
 (0)