@@ -17,6 +17,27 @@ export default class extends Controller {
1717 this . previousSourceType = this . selectedSourceType
1818 }
1919
20+ get locale ( ) {
21+ try {
22+ if ( typeof I18n !== 'undefined' && I18n && I18n . locale ) return I18n . locale
23+ } catch ( e ) { }
24+ try {
25+ const htmlLang = document . documentElement . getAttribute ( 'lang' )
26+ if ( htmlLang ) return htmlLang
27+ } catch ( e ) { }
28+ return 'en'
29+ }
30+
31+ get routeScopePath ( ) {
32+ try {
33+ if ( typeof BetterTogether !== 'undefined' && BetterTogether && BetterTogether . route_scope_path ) return BetterTogether . route_scope_path
34+ } catch ( e ) { }
35+ try {
36+ if ( this . element && this . element . dataset && this . element . dataset . routeScopePath ) return this . element . dataset . routeScopePath
37+ } catch ( e ) { }
38+ return ''
39+ }
40+
2041 handleSourceTypeChange ( ) {
2142 const selectedType = this . selectedSourceType
2243 if ( ! selectedType ) return
@@ -85,9 +106,11 @@ export default class extends Controller {
85106 }
86107
87108 async renderMarkdown ( content ) {
88- // Make an AJAX request to render the markdown on the server
89- const locale = document . documentElement . lang || 'en'
90- const response = await fetch ( `/${ locale } /content/blocks/preview_markdown` , {
109+ // Make an AJAX request to render the markdown on the server
110+ const locale = this . locale
111+ const routeScope = this . routeScopePath
112+ const scopeSegment = routeScope ? `/${ routeScope } ` : ''
113+ const response = await fetch ( `/${ locale } ${ scopeSegment } /content/blocks/preview_markdown` , {
91114 method : 'POST' ,
92115 headers : {
93116 'Content-Type' : 'application/json' ,
0 commit comments