From 5cd96d638c37dc7f92cb8b2fc84a3f7bfe7b7960 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 23 Sep 2020 22:44:54 +0100 Subject: rustdoc: Provide a way to set the default settings from Rust code rustdoc has various user-configurable preferences. These are recorded in web Local Storage (where available). But we want to provide a way to configure the default default, including for when web storage is not available. getSettingValue is the function responsible for looking up these settings. Here we make it fall back some in-DOM data, which ultimately comes from RenderOptions.default_settings. Using HTML data atrtributes is fairly convenient here, dsspite the need to transform between snake and kebab case to avoid the DOM converting kebab case to camel case (!) We cache the element and dataset lookup in a global variable, to ensure that getSettingValue remains fast. The DOM representation has to be in an element which precedes the inclusion of storage.js. That means it has to be in the and we should not use an empty
as the container (although most browsers will accept that). An empty