Настроить вывод из webdoc - PullRequest
4 голосов
/ 24 октября 2019

Я использую команду сообщества webdoc в Stata для Linux для создания документов Markdown.

Например:

webdoc init example, md replace logall plain
/***
# Exercise 1

Open the 1978 automobile data and summarize price and mileage.

***/
sysuse auto
summarize price mpg
/***

# Exercise 2

Run a regression of price on mileage and display the relation in a scatterplot.

***/
regress price mpg
twoway (scatter price mpg) (lfit price mpg)
webdoc graph

Как я могусохранить вывод как файл html вместо? Кроме того, есть ли способ изменить цвет заголовка на коричневый и цвет текста на синий? Наконец, возможно ли добавить раздел слева, чтобы включить заметки?

1 Ответ

3 голосов
/ 24 октября 2019

Вам необходимо напрямую включить соответствующий html, css и javascript код в файле Stata do.

Нижепростая реализация (сохраненная как example.do):

webdoc init example, replace logall plain
/***
<!DOCTYPE html>
<html>
    <head>
        <style>
            h1 {
              color:brown;
            }
            p {
              color:blue;
            }
            .container {
              display: flex;
            }
            #notes {
              display: none;
              flex-direction: column;
              flex-wrap: wrap;
              width: 125px;
            }
            .content {
              display: flex;
              flex-direction: column;
              padding-left: 150px
            } 
        </style>
    </head>
    <body>
        <div class="container">
            <div id="notes">
                <p>
                    This is the first note and it is not very long.
                </p>
                <p>
                    A shorter note.
                </p>
                <p>
                    This is the third and final note of this example. It is a
                    longer note which has no practical use.
                </p>
            </div>
            <div class="content">
                <button onclick="myNotes()">Notes</button>
                <h1>Exercise 1</h1>
                <p>
                    Open the 1978 automobile data and summarize price and
                    mileage.
                </p>
***/
                sysuse auto
                summarize price mpg
/***
                <h1>Exercise 2</h1>
                <p>
                    Run a regression of price on mileage and display the 
                    relation in a scatter plot.
                </p>
***/
                regress price mpg
                twoway (scatter price mpg) (lfit price mpg)
                webdoc graph
/***
            </div>
        </div>
        <script>
            function myNotes() {
                var n = document.getElementById("notes");
                if (n.style.display === "flex") {
                    n.style.display = "none";
                } 
                else {
                    n.style.display = "flex";
                }
            }
        </script>
   </body>
</html>
***/

Вы можете получить желаемый результат, включая вывод Stata, выполнив следующую команду:

webdoc do example.do

В качестве бонуса я сделал заметки складными;просто нажмите кнопку «Заметки», чтобы открыть или скрыть их при необходимости.

Наконец, вы можете удалить файлы журнала Stata следующим образом:

shell rm example_*.log

Результат безпримечания:

enter image description here


Результат с примечаниями:

enter image description here

...